﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace EasyTrader.Signal
{
    using PriceWaveList = List<EasyTrader.Wave.PriceWave>;
    using PriceSignalList = List<EasyTrader.Signal.PriceSignal>;
    using SysmanList = List<EasyTrader.Manager.SysManager>;


    public class SignalManagerEventArgs: EventArgs
    {
        private string m_HashCode = "";
        public string HashCode
        {
            get { return m_HashCode; }
            set { m_HashCode = value; }
        }
        private bool m_AutoOrder;
        public bool AutoOrder
        {
            get { return m_AutoOrder; }
            set { m_AutoOrder = value; }
        }
        public SignalManagerEventArgs(bool m, string a_HashCode)
        {
            this.m_AutoOrder = m;
            this.m_HashCode = a_HashCode;
        }
    }

    public class TotalSignalManager : EasyTrader.Signal.SignalManager
    {

        private SysmanList m_SysManagerList = new SysmanList();
        public SysmanList SysManagerList
        {
            get { return m_SysManagerList; }
            set { m_SysManagerList = value; }
        }


        public void CreateSysManagerList(EasyTrader.Order.OrderManager a_OrderManager)
        {
            EasyTrader.Manager.SysManager man = null;
            for (int i = 0; i < GlobalVar.SysNameArray.Length; i++)
            {
                switch (i)
                {
                    case 0:
                        man = new EasyTrader.Manager.JisuWaveHogaSummitSysManager();
                        //m_GSignalManager.SignalChanged += new Signal.TotalSignalManager.SignalManagerEventHandler(On_SignalChaged);
                        break;
                    case 1:
                        man = new EasyTrader.Manager.JisuWaveSysManager();
                        break;
                    case 2:
                        man = new EasyTrader.Manager.HogaWaveSysManager();
                        break;
                    case 3:
                        man = new EasyTrader.Manager.HogaSquareOccSysManager();
                        break;
                    case 4:
                        man = new EasyTrader.Manager.HogaSummitSysManager();
                        break;
                    case 5:
                        man = new EasyTrader.Manager.CallPutSquareOccSysManager();
                        break;
                    case 6:
                        man = new EasyTrader.Manager.PureHogaSummitSysManager();
                        break;
                    case 7:
                        man = new EasyTrader.Manager.LooseHogaSummitSysManager();
                        break;
                    case 8:
                        man = new EasyTrader.Manager.CallPutInvDivSysManager();
                        break;
                    case 9:
                        man = new EasyTrader.Manager.TipAttackSysManager();
                        break;
                    case 10:
                        man = new EasyTrader.Manager.OptPriceSysManager();
                        break;
                    case 11:
                        man = new EasyTrader.Manager.OptMainPriceSysManager();
                        break;
                    case 12:
                        man = new EasyTrader.Manager.OptCenterPriceSysManager();
                        break;
                    case 13:
                        man = new EasyTrader.Manager.OptBothSellSysManager();
                        break;
                    case 14:
                        man = new EasyTrader.Manager.OptBendSysManager();
                        break;
                    case 15:
                        man = new EasyTrader.Manager.SubjectSysManager();
                        break;
                }
                man.TotalSigMan = this;
                man.SysName = GlobalVar.SysNameArray[i];
                man.SysType = i;
                man.LogFileName = GlobalVar.SysNameArray[i] + "_Log.txt";
                man.OrderMan = a_OrderManager;
                m_SysManagerList.Add(man);
            }
        }

        public void UpdateSysState()
        {
            for (int i = 0; i < m_SysManagerList.Count; i++)
            {
                EasyTrader.Manager.SysManager sysMan = m_SysManagerList[i];
                if (i == 0)
                {
                    EasyTrader.Manager.JisuWaveHogaSummitSysManager oriMan = (EasyTrader.Manager.JisuWaveHogaSummitSysManager)sysMan;
                    oriMan.UpdateSysState();
                }
                else if (i == 1)
                {
                    EasyTrader.Manager.JisuWaveSysManager oriMan = (EasyTrader.Manager.JisuWaveSysManager)sysMan;
                    oriMan.UpdateSysState();
                }
                else if (i == 2)
                {
                    EasyTrader.Manager.HogaWaveSysManager oriMan = (EasyTrader.Manager.HogaWaveSysManager)sysMan;
                    oriMan.UpdateSysState();
                }
                else if (i == 3)
                {
                    EasyTrader.Manager.HogaSquareOccSysManager oriMan = (EasyTrader.Manager.HogaSquareOccSysManager)sysMan;
                    oriMan.UpdateSysState();
                }
                else if (i == 4)
                {
                    EasyTrader.Manager.HogaSummitSysManager oriMan = (EasyTrader.Manager.HogaSummitSysManager)sysMan;
                    oriMan.UpdateSysState();
                }
                else if (i == 5)
                {
                    EasyTrader.Manager.CallPutSquareOccSysManager oriMan = (EasyTrader.Manager.CallPutSquareOccSysManager)sysMan;
                    oriMan.UpdateSysState();
                }
                else if (i == 6)
                {
                    EasyTrader.Manager.PureHogaSummitSysManager oriMan = (EasyTrader.Manager.PureHogaSummitSysManager)sysMan;
                    oriMan.UpdateSysState();
                }
                else if (i == 7)
                {
                    EasyTrader.Manager.LooseHogaSummitSysManager oriMan = (EasyTrader.Manager.LooseHogaSummitSysManager)sysMan;
                    oriMan.UpdateSysState();
                }
                else if (i == 8)
                {
                    EasyTrader.Manager.CallPutInvDivSysManager oriMan = (EasyTrader.Manager.CallPutInvDivSysManager)sysMan;
                    oriMan.UpdateSysState();
                }
                else if (i == 9)
                {
                    EasyTrader.Manager.TipAttackSysManager oriMan = (EasyTrader.Manager.TipAttackSysManager)sysMan;
                    oriMan.UpdateSysState();
                }
                else if (i == 10)
                {
                    EasyTrader.Manager.OptPriceSysManager oriMan = (EasyTrader.Manager.OptPriceSysManager)sysMan;
                    // 먼저 상태를 준비 시키고 그 다음에 상태를 업데이트 시킨다.
                    oriMan.PrepareState();
                    oriMan.UpdateSysState();
                }
                else if (i == 11)
                {
                    EasyTrader.Manager.OptMainPriceSysManager oriMan = (EasyTrader.Manager.OptMainPriceSysManager)sysMan;
                    // 먼저 상태를 준비 시키고 그 다음에 상태를 업데이트 시킨다.
                    oriMan.PrepareState();
                    oriMan.UpdateSysState();
                }
                else if (i == 12)
                {
                    EasyTrader.Manager.OptCenterPriceSysManager oriMan = (EasyTrader.Manager.OptCenterPriceSysManager)sysMan;
                    // 먼저 상태를 준비 시키고 그 다음에 상태를 업데이트 시킨다.
                    oriMan.PrepareState();
                    oriMan.UpdateSysState();
                }
                else if (i == 13)
                {
                    EasyTrader.Manager.OptBothSellSysManager oriMan = (EasyTrader.Manager.OptBothSellSysManager)sysMan;
                    // 먼저 상태를 준비 시키고 그 다음에 상태를 업데이트 시킨다.
                    oriMan.PrepareState();
                    oriMan.UpdateSysState();
                }
                else if (i == 14)
                {
                    EasyTrader.Manager.OptBendSysManager oriMan = (EasyTrader.Manager.OptBendSysManager)sysMan;
                    // 먼저 상태를 준비 시키고 그 다음에 상태를 업데이트 시킨다.
                    oriMan.PrepareState();
                    oriMan.UpdateSysState();
                }
                else if (i == 15)
                {
                    EasyTrader.Manager.SubjectSysManager oriMan = (EasyTrader.Manager.SubjectSysManager)sysMan;
                    oriMan.UpdateSysState();
                }
            }
        }


        public void UpdateSysState(int a_SysType)
        {
            int i = a_SysType;
            EasyTrader.Manager.SysManager sysMan = m_SysManagerList[i];
            if (i == 0)
            {
                EasyTrader.Manager.JisuWaveHogaSummitSysManager oriMan = (EasyTrader.Manager.JisuWaveHogaSummitSysManager)sysMan;
                oriMan.UpdateSysState();
            }
            else if (i == 1)
            {
                EasyTrader.Manager.JisuWaveSysManager oriMan = (EasyTrader.Manager.JisuWaveSysManager)sysMan;
                oriMan.UpdateSysState();
            }
            else if (i == 2)
            {
                EasyTrader.Manager.HogaWaveSysManager oriMan = (EasyTrader.Manager.HogaWaveSysManager)sysMan;
                oriMan.UpdateSysState();
            }
            else if (i == 3)
            {
                EasyTrader.Manager.HogaSquareOccSysManager oriMan = (EasyTrader.Manager.HogaSquareOccSysManager)sysMan;
                oriMan.UpdateSysState();
            }
            else if (i == 4)
            {
                EasyTrader.Manager.HogaSummitSysManager oriMan = (EasyTrader.Manager.HogaSummitSysManager)sysMan;
                oriMan.UpdateSysState();
            }
            else if (i == 5)
            {
                EasyTrader.Manager.CallPutSquareOccSysManager oriMan = (EasyTrader.Manager.CallPutSquareOccSysManager)sysMan;
                oriMan.UpdateSysState();
            }
            else if (i == 6)
            {
                EasyTrader.Manager.PureHogaSummitSysManager oriMan = (EasyTrader.Manager.PureHogaSummitSysManager)sysMan;
                oriMan.UpdateSysState();
            }
            else if (i == 7)
            {
                EasyTrader.Manager.LooseHogaSummitSysManager oriMan = (EasyTrader.Manager.LooseHogaSummitSysManager)sysMan;
                oriMan.UpdateSysState();
            }
            else if (i == 8)
            {
                EasyTrader.Manager.CallPutInvDivSysManager oriMan = (EasyTrader.Manager.CallPutInvDivSysManager)sysMan;
                oriMan.UpdateSysState();
            }
            else if (i == 9)
            {
                EasyTrader.Manager.TipAttackSysManager oriMan = (EasyTrader.Manager.TipAttackSysManager)sysMan;
                oriMan.UpdateSysState();
            }
            else if (i == 10)
            {
                EasyTrader.Manager.OptPriceSysManager oriMan = (EasyTrader.Manager.OptPriceSysManager)sysMan;
                // 먼저 상태를 준비 시키고 그 다음에 상태를 업데이트 시킨다.
                oriMan.PrepareState();
                oriMan.UpdateSysState();
            }
            else if (i == 11)
            {
                EasyTrader.Manager.OptMainPriceSysManager oriMan = (EasyTrader.Manager.OptMainPriceSysManager)sysMan;
                // 먼저 상태를 준비 시키고 그 다음에 상태를 업데이트 시킨다.
                oriMan.PrepareState();
                oriMan.UpdateSysState();
            }
            else if (i == 12)
            {
                EasyTrader.Manager.OptCenterPriceSysManager oriMan = (EasyTrader.Manager.OptCenterPriceSysManager)sysMan;
                // 먼저 상태를 준비 시키고 그 다음에 상태를 업데이트 시킨다.
                oriMan.PrepareState();
                oriMan.UpdateSysState();
            }
            else if (i == 13)
            {
                EasyTrader.Manager.OptBothSellSysManager oriMan = (EasyTrader.Manager.OptBothSellSysManager)sysMan;
                // 먼저 상태를 준비 시키고 그 다음에 상태를 업데이트 시킨다.
                oriMan.PrepareState();
                oriMan.UpdateSysState();
            }
            else if (i == 14)
            {
                EasyTrader.Manager.OptBendSysManager oriMan = (EasyTrader.Manager.OptBendSysManager)sysMan;
                // 먼저 상태를 준비 시키고 그 다음에 상태를 업데이트 시킨다.
                oriMan.PrepareState();
                oriMan.UpdateSysState();
            }
            else if (i == 15)
            {
                EasyTrader.Manager.SubjectSysManager oriMan = (EasyTrader.Manager.SubjectSysManager)sysMan;
                oriMan.UpdateSysState();
            }
        }

        public PriceSignalList FindSignalListBySysType(int a_SysType)
        {
            bool LastSignalFired = FindLastSignalFired(a_SysType);
            
            if (LastSignalFired == false)
                return FindSignalList(a_SysType);
            else
                return FindStateList(a_SysType);
        }

        public bool FindLastSignalFired(int a_SysType)
        {
            bool LastSignalFired = false;
            if (a_SysType == GlobalVar.SysTypeJisuWaveHogaSummit)
            {
                LastSignalFired = JisuWaveHogaSummitSysVar.LastSignalFired;
            }
            else if (a_SysType == GlobalVar.SysTypeJisuWave)
            {
                LastSignalFired = JisuWaveSysVar.LastSignalFired;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaWave)
            {
                LastSignalFired = HogaWaveSysVar.LastSignalFired;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSquareOcc)
            {
                LastSignalFired = HogaSquareOccSysVar.LastSignalFired;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSummit)
            {
                LastSignalFired = HogaSummitSysVar.LastSignalFired;
            }
            else if (a_SysType == GlobalVar.SysTypeCallPutSquareOcc)
            {
                LastSignalFired = CallPutSquareOccSysVar.LastSignalFired;
            }
            else if (a_SysType == GlobalVar.SysTypePureHogaSummit)
            {
                LastSignalFired = PureHogaSummitSysVar.LastSignalFired;
            }
            else if (a_SysType == GlobalVar.SysTypeLooseHogaSummit)
            {
                LastSignalFired = LooseHogaSummitSysVar.LastSignalFired;
            }
            else if (a_SysType == GlobalVar.SysTypeCallPutInvDiv)
            {
                LastSignalFired = CallPutInvDivSysVar.LastSignalFired;
            }
            else if (a_SysType == GlobalVar.SysTypeTipAttack)
            {
                LastSignalFired = TipAttackSysVar.LastSignalFired;
            }
            else if (a_SysType == GlobalVar.SysTypeOptPrice)
            {
                LastSignalFired = OptPriceSysVar.LastSignalFired;
            }

            return LastSignalFired;
        }

        public PriceSignalList FindSignalList(int a_SysType)
        {
            for (int i = 0; i < m_SysManagerList.Count; i++)
            {
                EasyTrader.Manager.SysManager sysMan = m_SysManagerList[i];
                if (sysMan.SysType == a_SysType)
                    return sysMan.PriceSignalList;
            }

            return null;
        }

        public PriceSignalList FindStateList(int a_SysType)
        {
            for (int i = 0; i < m_SysManagerList.Count; i++)
            {
                EasyTrader.Manager.SysManager sysMan = m_SysManagerList[i];
                if (sysMan.SysType == a_SysType)
                    return sysMan.PriceStateList;
            }

            return null;
        }


        public int GetBuySellCrossedCount(int a_StartIndex, int a_EndIndex)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            return GetCrossedCount(a_StartIndex, a_EndIndex, curTable, "매수총호가건수", "매도총호가건수");
        }

        private int GetCrossedCount(int a_StartIndex, int a_EndIndex, EasyTrader.DataSet.ETDataTable a_Table, string a_FirstColName, string a_SecondColName)
        {
            if (a_Table == null)
                return -1;
            int rowCount = a_Table.GetRowCount();
            if (rowCount == 0)
                return -1;
            if (a_StartIndex < 0 || a_EndIndex < 0)
                return -1;
            if (a_StartIndex >= a_EndIndex)
                return -1;

            DataRow row = a_Table.Rows[a_StartIndex];
            double bidsValue = Convert.ToDouble(row[a_FirstColName]);
            double asksValue = Convert.ToDouble(row[a_SecondColName]);
            double delta = bidsValue - asksValue;
            int oldTrend = GlobalVar.PriceFlat;
            if (delta > 0)
                oldTrend = GlobalVar.PriceUp;
            else if (delta < 0)
                oldTrend = GlobalVar.PriceDown;
            int crossCount = 0;

            a_EndIndex = Math.Min(a_EndIndex, rowCount - 1);

            for (int i = a_StartIndex; i < a_EndIndex; i++)
            {
                row = a_Table.Rows[i];
                try
                {
                    // 값이 없을 경우는 넘어 간다.
                    if (row[a_FirstColName] == DBNull.Value)
                        continue;

                    bidsValue = Convert.ToDouble(row[a_FirstColName]);
                    asksValue = Convert.ToDouble(row[a_SecondColName]);

                    delta = bidsValue - asksValue;
                    int trend = GlobalVar.PriceFlat;
                    if (delta > 0)
                        trend = GlobalVar.PriceUp;
                    else if (delta < 0)
                        trend = GlobalVar.PriceDown;
                    if (oldTrend != GlobalVar.PriceFlat && trend != GlobalVar.PriceFlat &&
                        oldTrend != trend)
                    {
                        crossCount++;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            return crossCount;
        }

        // 분을 중심으로한 시간 인덱스 : 9시0분이 0이다
        private int m_CurIndex = 0;
        public int CurIndex
        {
            get { return m_CurIndex; }
            set { m_CurIndex = value; }
        }
        public double m_WaveSumUp = 0.0;
        public double WaveSumUp
        {
            get { return m_WaveSumUp; }
            set { m_WaveSumUp = value; }
        }
        public double m_WaveSumDown = 0.0;
        public double WaveSumDown
        {
            get { return m_WaveSumDown; }
            set { m_WaveSumDown = value; }
        }

        public int m_CrossCount = 0;
        public int CrossCount
        {
            get { return m_CrossCount; }
            set { m_CrossCount = value; }
        }
        // 청산 신호 목록 - 이 신호는 
        // 메인신호를 기반으로 진입과 청산을 반복한다.
        protected PriceSignalList m_MainSignalList = new PriceSignalList();
        public PriceSignalList MainSignalList
        {
            get { return m_MainSignalList; }
            set { m_MainSignalList = value; }
        }
        private EasyTrader.Signal.HighLowInfo m_SignalHighLowInfo = new EasyTrader.Signal.HighLowInfo();
        public EasyTrader.Signal.HighLowInfo SignalHighLowInfo
        {
            get { return m_SignalHighLowInfo; }
            set { m_SignalHighLowInfo = value; }
        }

#region Event Fire

        public event SysManagerEventHandler LastSignalFired;

        public virtual void FireLastSignal(bool a_AutoOrder, int a_SysType)
        {
            SysManagerEventArgs args = new SysManagerEventArgs(a_AutoOrder, a_SysType);
            OnLastSignalFired(args);
        }

        public virtual void OnLastSignalFired(SysManagerEventArgs e)
        {
            if (LastSignalFired != null)
                LastSignalFired(this, e);
        }
#endregion
        
        

        private EasyTrader.Wave.PriceWave m_SignalWave = new EasyTrader.Wave.PriceWave();
        public EasyTrader.Wave.PriceWave SignalWave
        {
            get { return m_SignalWave; }
            set { m_SignalWave = value; }
        }

        private EasyTrader.Wave.PriceWave m_IndexWave = new EasyTrader.Wave.PriceWave();
        public EasyTrader.Wave.PriceWave IndexWave
        {
            get { return m_IndexWave; }
            set { m_IndexWave = value; }
        }
        
        private EasyTrader.Signal.PriceSignal m_CurSignal = new EasyTrader.Signal.PriceSignal();
        public EasyTrader.Signal.PriceSignal CurSignal
        {
            get { return m_CurSignal; }
            set { m_CurSignal = value; }
        }

        private ForecastingInfo m_LastSignalRegression = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo LastSignalRegression
        {
            get { return m_LastSignalRegression; }
            set { m_LastSignalRegression = value; }
        }
        private ForecastingInfo m_CurWaveRegression = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo CurWaveRegression
        {
            get { return m_CurWaveRegression; }
            set { m_CurWaveRegression = value; }
        }

        public void InitHogaChartCtrl()
        {
            if (m_ETHogaSignalManager != null && m_EasyTraderDataSet != null)
            {
                m_ETHogaSignalManager.EasyTraderDataSet = m_EasyTraderDataSet;
                m_ETHogaSignalManager.InitChartCtrl();
            }
        }

        public void InitCallPutChartCtrl()
        {
            if (m_ETSubjectSignalManager != null && m_EasyTraderDataSet != null)
            {
                m_ETSubjectSignalManager.EasyTraderDataSet = m_EasyTraderDataSet;
                m_ETSubjectSignalManager.InitChartCtrl();
            }
        }

        public void WriteSignalLog(string a_StateMsg, EasyTrader.Signal.PriceSignal a_Signal)
        {
            string logMsg = "=======> 신호발생 :: ";
            logMsg += "발생상황 : " + a_StateMsg;
            logMsg += ", 시간 : " + a_Signal.Time.ToString();
            logMsg += ", X : " + a_Signal.X.ToString();
            logMsg += ", Y : " + a_Signal.Y.ToString("F2");
            logMsg += ", 신호종류 : ";
            if (a_Signal.Type == GlobalVar.SignalNone)
            {
                logMsg += "신호없음";
            }
            else if (a_Signal.Type == GlobalVar.SignalSell)
            {
                logMsg += "매도";
            }
            else if (a_Signal.Type == GlobalVar.SignalBuy)
            {
                logMsg += "매수";
            }
            else
            {
                logMsg += "알수없음";
            }

            logMsg += ", 신호상태 : ";
            if (a_Signal.SignalState == GlobalVar.SignalStateFirst)
            {
                logMsg += "첫신호";
            }
            else if (a_Signal.SignalState == GlobalVar.SignalStateTrans)
            {
                logMsg += "전환신호";
            }
            else if (a_Signal.SignalState == GlobalVar.SignalStateOver)
            {
                logMsg += "돌파신호";
            }
            else if (a_Signal.SignalState == GlobalVar.SignalStateLiquid)
            {
                logMsg += "청산신호";
            }
            else if (a_Signal.SignalState == GlobalVar.SignalStateCorrect)
            {
                logMsg += "수정신호";
            }
            else
            {
                logMsg += "상태없음";
            }

            logMsg += ", 상태번호 : ";
            if (a_Signal.StateNumber == GlobalVar.SignalStateFirst)
            {
                logMsg += "첫신호";
            }
            else if (a_Signal.StateNumber == GlobalVar.SignalStateTrans)
            {
                logMsg += "전환신호";
            }
            else if (a_Signal.StateNumber == GlobalVar.SignalStateOver)
            {
                logMsg += "돌파신호";
            }
            else if (a_Signal.StateNumber == GlobalVar.SignalStateLiquid)
            {
                logMsg += "청산신호";
            }
            else if (a_Signal.StateNumber == GlobalVar.SignalStateCorrect)
            {
                logMsg += "수정신호";
            }
            else
            {
                logMsg += "상태없음";
            }
            logMsg += ", 일일진폭 : " + (a_Signal.DayMax - a_Signal.DayMin).ToString("F2");
            logMsg += ", 일일종가진폭 : " + (a_Signal.DayCloseMax - a_Signal.DayCloseMin).ToString("F2");

            logMsg += ", 신파진폭 : " + (a_Signal.SignalMax - a_Signal.SignalMin).ToString("F2");
            logMsg += ", 신파종가진폭 : " + (a_Signal.SignalCloseMax - a_Signal.SignalCloseMin).ToString("F2");

            logMsg += ", 파동 StartX : " + a_Signal.CurWaveStartX.ToString();
            logMsg += ", 파동 StartY : " + a_Signal.CurWaveStartY.ToString("F2");
            logMsg += ", 파동 EndX : " + a_Signal.CurWaveEndX.ToString();
            logMsg += ", 파동 EndY : " + a_Signal.CurWaveEndY.ToString("F2");
            logMsg += ", 파동 방향 : ";
            if (a_Signal.CurWaveSlope == GlobalVar.PriceUp)
                logMsg += "상승";
            else if (a_Signal.CurWaveSlope == GlobalVar.PriceDown)
                logMsg += "하락";
            else
                logMsg += "방향없음";

            logMsg += ", 파동 최고가 : " + a_Signal.CurWaveHigh.ToString("F2");
            logMsg += ", 파동 최저가 : " + a_Signal.CurWaveLow.ToString("F2");
            logMsg += ", 파동 종가최고가 : " + a_Signal.CurWaveCloseMax.ToString("F2");
            logMsg += ", 파동 종가최저가 : " + a_Signal.CurWaveCloseMin.ToString("F2");

            logMsg += ", 일고가 : " + a_Signal.DayMax;
            logMsg += ", 일저가 : " + a_Signal.DayMin;

            logMsg += ", 종고가 : " + a_Signal.DayCloseMax;
            logMsg += ", 종저가 : " + a_Signal.DayCloseMin;

            logMsg += ", 신호고가 : " + a_Signal.SignalMax;
            logMsg += ", 신호저가 : " + a_Signal.SignalMin;

            logMsg += ", 신호종고가 : " + a_Signal.SignalCloseMax;
            logMsg += ", 신호종저가 : " + a_Signal.SignalCloseMin;
            logMsg += ", 호가신호파동종류 : ";
            if (a_Signal.WaveType == GlobalVar.WaveTypeBuy)
                logMsg += "매수파동";
            else if (a_Signal.WaveType == GlobalVar.WaveTypeSell)
                logMsg += "매도파동";
            else
                logMsg += "파동타입없음";
            logMsg += ", 매수일최고가 : " + a_Signal.BuyDayHigh;
            logMsg += ", 매도일최고가 : " + a_Signal.SellDayHigh;
            logMsg += ", 매수신호파동높이 : " + a_Signal.SignalBuyHeight;
            logMsg += ", 매도신호파동높이 : " + a_Signal.SignalSellHeight;
            GlobalVar.WriteLog(logMsg);
        }

        public void WriteSignalLog(string a_StateMsg, string a_FileName, EasyTrader.Signal.PriceSignal a_Signal)
        {
            string logMsg = "=======> 신호발생 :: ";
            logMsg += "발생상황 : " + a_StateMsg;
            logMsg += ", 시간 : " + a_Signal.Time.ToString();
            logMsg += ", X : " + a_Signal.X.ToString();
            logMsg += ", Y : " + a_Signal.Y.ToString("F2");
            logMsg += ", 신호종류 : ";
            if (a_Signal.Type == GlobalVar.SignalNone)
            {
                logMsg += "신호없음";
            }
            else if (a_Signal.Type == GlobalVar.SignalSell)
            {
                logMsg += "매도";
            }
            else if (a_Signal.Type == GlobalVar.SignalBuy)
            {
                logMsg += "매수";
            }
            else
            {
                logMsg += "알수없음";
            }

            logMsg += ", 신호상태 : ";
            if (a_Signal.SignalState == GlobalVar.SignalStateFirst)
            {
                logMsg += "첫신호";
            }
            else if (a_Signal.SignalState == GlobalVar.SignalStateTrans)
            {
                logMsg += "전환신호";
            }
            else if (a_Signal.SignalState == GlobalVar.SignalStateOver)
            {
                logMsg += "돌파신호";
            }
            else if (a_Signal.SignalState == GlobalVar.SignalStateLiquid)
            {
                logMsg += "청산신호";
            }
            else if (a_Signal.SignalState == GlobalVar.SignalStateCorrect)
            {
                logMsg += "수정신호";
            }
            else
            {
                logMsg += "상태없음";
            }

            logMsg += ", 상태번호 : ";
            logMsg += a_Signal.StateNumber.ToString();

            logMsg += ", 일일진폭 : " + (a_Signal.DayMax - a_Signal.DayMin).ToString("F2");
            logMsg += ", 일일종가진폭 : " + (a_Signal.DayCloseMax - a_Signal.DayCloseMin).ToString("F2");

            logMsg += ", 신파진폭 : " + (a_Signal.SignalMax - a_Signal.SignalMin).ToString("F2");
            logMsg += ", 신파종가진폭 : " + (a_Signal.SignalCloseMax - a_Signal.SignalCloseMin).ToString("F2");

            logMsg += ", 파동 StartX : " + a_Signal.CurWaveStartX.ToString();
            logMsg += ", 파동 StartY : " + a_Signal.CurWaveStartY.ToString("F2");
            logMsg += ", 파동 EndX : " + a_Signal.CurWaveEndX.ToString();
            logMsg += ", 파동 EndY : " + a_Signal.CurWaveEndY.ToString("F2");
            logMsg += ", 파동 방향 : ";
            if (a_Signal.CurWaveSlope == GlobalVar.PriceUp)
                logMsg += "상승";
            else if (a_Signal.CurWaveSlope == GlobalVar.PriceDown)
                logMsg += "하락";
            else
                logMsg += "방향없음";

            logMsg += ", 파동 최고가 : " + a_Signal.CurWaveHigh.ToString("F2");
            logMsg += ", 파동 최저가 : " + a_Signal.CurWaveLow.ToString("F2");
            logMsg += ", 파동 종가최고가 : " + a_Signal.CurWaveCloseMax.ToString("F2");
            logMsg += ", 파동 종가최저가 : " + a_Signal.CurWaveCloseMin.ToString("F2");

            logMsg += ", 일고가 : " + a_Signal.DayMax;
            logMsg += ", 일저가 : " + a_Signal.DayMin;

            logMsg += ", 종고가 : " + a_Signal.DayCloseMax;
            logMsg += ", 종저가 : " + a_Signal.DayCloseMin;

            logMsg += ", 신호고가 : " + a_Signal.SignalMax;
            logMsg += ", 신호저가 : " + a_Signal.SignalMin;

            logMsg += ", 신호종고가 : " + a_Signal.SignalCloseMax;
            logMsg += ", 신호종저가 : " + a_Signal.SignalCloseMin;
            logMsg += ", 호가신호파동종류 : ";
            if (a_Signal.WaveType == GlobalVar.WaveTypeBuy)
                logMsg += "매수파동";
            else if (a_Signal.WaveType == GlobalVar.WaveTypeSell)
                logMsg += "매도파동";
            else
                logMsg += "파동타입없음";
            logMsg += ", 매수일최고가 : " + a_Signal.BuyDayHigh;
            logMsg += ", 매도일최고가 : " + a_Signal.SellDayHigh;
            logMsg += ", 매수신호파동높이 : " + a_Signal.SignalBuyHeight;
            logMsg += ", 매도신호파동높이 : " + a_Signal.SignalSellHeight;
            GlobalVar.WriteLogWithFileName(logMsg, a_FileName);
        }

        public void WriteStateLog(string a_StateMsg, string a_FileName, EasyTrader.Signal.PriceSignal a_Signal)
        {
            string logMsg = "=======> 전환발생 :: ";
            logMsg += "발생상황 : " + a_StateMsg;
            logMsg += ", 시간 : " + a_Signal.Time.ToString();
            logMsg += ", X : " + a_Signal.X.ToString();
            logMsg += ", Y : " + a_Signal.Y.ToString("F2");
            logMsg += ", 전환종류 : ";
            if (a_Signal.Type == GlobalVar.SignalNone)
            {
                logMsg += "전환없음";
            }
            else if (a_Signal.Type == GlobalVar.SignalSell)
            {
                logMsg += "매도";
            }
            else if (a_Signal.Type == GlobalVar.SignalBuy)
            {
                logMsg += "매수";
            }
            else
            {
                logMsg += "알수없음";
            }

            logMsg += ", 전환상태 : ";
            if (a_Signal.SignalState == GlobalVar.SignalStateFirst)
            {
                logMsg += "첫전환";
            }
            else if (a_Signal.SignalState == GlobalVar.SignalStateTrans)
            {
                logMsg += "일반전환";
            }
            else if (a_Signal.SignalState == GlobalVar.SignalStateOver)
            {
                logMsg += "돌파전환";
            }
            else
            {
                logMsg += "상태없음";
            }

            logMsg += ", 상태번호 : ";
            logMsg += a_Signal.StateNumber.ToString();

            logMsg += ", 일일진폭 : " + (a_Signal.DayMax - a_Signal.DayMin).ToString("F2");
            logMsg += ", 일일종가진폭 : " + (a_Signal.DayCloseMax - a_Signal.DayCloseMin).ToString("F2");

            logMsg += ", 신파진폭 : " + (a_Signal.SignalMax - a_Signal.SignalMin).ToString("F2");
            logMsg += ", 신파종가진폭 : " + (a_Signal.SignalCloseMax - a_Signal.SignalCloseMin).ToString("F2");

            logMsg += ", 파동 StartX : " + a_Signal.CurWaveStartX.ToString();
            logMsg += ", 파동 StartY : " + a_Signal.CurWaveStartY.ToString("F2");
            logMsg += ", 파동 EndX : " + a_Signal.CurWaveEndX.ToString();
            logMsg += ", 파동 EndY : " + a_Signal.CurWaveEndY.ToString("F2");
            logMsg += ", 파동 방향 : ";
            if (a_Signal.CurWaveSlope == GlobalVar.PriceUp)
                logMsg += "상승";
            else if (a_Signal.CurWaveSlope == GlobalVar.PriceDown)
                logMsg += "하락";
            else
                logMsg += "방향없음";

            logMsg += ", 파동 최고가 : " + a_Signal.CurWaveHigh.ToString("F2");
            logMsg += ", 파동 최저가 : " + a_Signal.CurWaveLow.ToString("F2");
            logMsg += ", 파동 종가최고가 : " + a_Signal.CurWaveCloseMax.ToString("F2");
            logMsg += ", 파동 종가최저가 : " + a_Signal.CurWaveCloseMin.ToString("F2");

            logMsg += ", 일고가 : " + a_Signal.DayMax;
            logMsg += ", 일저가 : " + a_Signal.DayMin;

            logMsg += ", 종고가 : " + a_Signal.DayCloseMax;
            logMsg += ", 종저가 : " + a_Signal.DayCloseMin;

            logMsg += ", 신호고가 : " + a_Signal.SignalMax;
            logMsg += ", 신호저가 : " + a_Signal.SignalMin;

            logMsg += ", 신호종고가 : " + a_Signal.SignalCloseMax;
            logMsg += ", 신호종저가 : " + a_Signal.SignalCloseMin;
            logMsg += ", 호가신호파동종류 : ";
            if (a_Signal.WaveType == GlobalVar.WaveTypeBuy)
                logMsg += "매수파동";
            else if (a_Signal.WaveType == GlobalVar.WaveTypeSell)
                logMsg += "매도파동";
            else
                logMsg += "파동타입없음";
            logMsg += ", 매수일최고가 : " + a_Signal.BuyDayHigh;
            logMsg += ", 매도일최고가 : " + a_Signal.SellDayHigh;
            logMsg += ", 매수신호파동높이 : " + a_Signal.SignalBuyHeight;
            logMsg += ", 매도신호파동높이 : " + a_Signal.SignalSellHeight;
            GlobalVar.WriteLogWithFileName(logMsg, a_FileName);
        }

        public void WriteHogaLog(int a_CurIndex)
        {
            DateTime now = DateTime.Now;
            if ((now.Second % 10) != 0)
                return;
            string logMsg = "호가 상태 :: 인덱스 : " + a_CurIndex.ToString();
            logMsg += ", 시간 : " + GlobalVar.TimeToIntEx().ToString();
            logMsg += ", 매수호가 : " + m_HogaBuyInfo.PureEndY.ToString();
            logMsg += ", 매도호가 : " + m_HogaSellInfo.PureEndY.ToString();
            logMsg += ", 매수호가각도 : " + m_HogaBuyInfo.Angle.ToString("F2");
            logMsg += ", 매도호가각도 : " + m_HogaSellInfo.Angle.ToString("F2");
            logMsg += ", 호가건수차이 : " + (m_HogaBuyInfo.PureEndY - m_HogaSellInfo.PureEndY).ToString();
            logMsg += ", 수렴발산값 : " + m_ETHogaSignalManager.InvDivBuySell.ToString();
            GlobalVar.WriteLog(logMsg);
        }

        public void WriteHogaRatioLog(int a_CurIndex, int a_BuyTimeOcc, int a_SellTimeOcc, int a_BuySquareOcc, int a_SellSquareOcc, int a_BSPower, int a_HogaLimit)
        {
            DateTime now = DateTime.Now;
            if ((now.Second % 10) != 0)
                return;
            string logMsg = "호가 비율 상태 :: 인덱스 : " + a_CurIndex.ToString();
            logMsg += ", 시간 : " + GlobalVar.TimeToIntEx().ToString();
            logMsg += ", 매수시간점유율 : " + a_BuyTimeOcc.ToString() + "%";
            logMsg += ", 매도시간점유율 : " + a_SellTimeOcc.ToString() + "%";
            logMsg += ", 매수공간점유율 : " + a_BuySquareOcc.ToString() + "%";
            logMsg += ", 매도공간점유율 : " + a_SellSquareOcc.ToString() + "%";
            logMsg += ", 현재청산호가건수 : " + a_HogaLimit.ToString();
            if (a_BSPower == GlobalVar.PowerBuy)
            {
                logMsg += ", 매도매수우위 : 매수우위";
            }
            else if (a_BSPower == GlobalVar.PowerSell)
            {
                logMsg += ", 매도매수우위 : 매도우위";
            }
            else
            {
                logMsg += ", 매도매수우위 : 우위없음";
            }
            
            GlobalVar.WriteLog(logMsg);
        }

        private void WriteHogaRatioLog(int a_CurIndex, int a_BuyTimeOcc, int a_SellTimeOcc, int a_BuySquareOcc, int a_SellSquareOcc, int a_BSPower, int a_HogaLimit, string a_LogFileName)
        {
            DateTime now = DateTime.Now;
            if ((now.Second % 10) != 0)
                return;
            string logMsg = "호가 비율 상태 :: 인덱스 : " + a_CurIndex.ToString();
            logMsg += ", 시간 : " + GlobalVar.TimeToIntEx().ToString();
            logMsg += ", 매수시간점유율 : " + a_BuyTimeOcc.ToString() + "%";
            logMsg += ", 매도시간점유율 : " + a_SellTimeOcc.ToString() + "%";
            logMsg += ", 매수공간점유율 : " + a_BuySquareOcc.ToString() + "%";
            logMsg += ", 매도공간점유율 : " + a_SellSquareOcc.ToString() + "%";
            logMsg += ", 현재청산호가건수 : " + a_HogaLimit.ToString();
            if (a_BSPower == GlobalVar.PowerBuy)
            {
                logMsg += ", 매도매수우위 : 매수우위";
            }
            else if (a_BSPower == GlobalVar.PowerSell)
            {
                logMsg += ", 매도매수우위 : 매도우위";
            }
            else
            {
                logMsg += ", 매도매수우위 : 우위없음";
            }

            GlobalVar.WriteLogWithFileName(logMsg, a_LogFileName);
        }

        public void WriteStateLog(int a_CurIndex, EasyTrader.Signal.PriceSignal a_Signal)
        {
            DateTime now = DateTime.Now;
            if ((now.Second % 10) != 0)
                return;

            string logMsg = "시스템 상태 :: 인덱스 : " + a_CurIndex.ToString();
            logMsg += ", 시간 : " + GlobalVar.TimeToIntEx().ToString();
            //EasyTrader.Signal.PriceSignal a_Signal = GetLastSignal();
            if (a_Signal != null)
            {
                logMsg += ", 현재신호 : ";
                if (a_Signal.Type == GlobalVar.SignalNone)
                {
                    logMsg += "신호없음";
                }
                else if (a_Signal.Type == GlobalVar.SignalSell)
                {
                    logMsg += "매도";
                }
                else if (a_Signal.Type == GlobalVar.SignalBuy)
                {
                    logMsg += "매수";
                }
                else
                {
                    logMsg += "알수없음";
                }

                logMsg += ", 신호상태 : ";
                if (a_Signal.SignalState == GlobalVar.SignalStateFirst)
                {
                    logMsg += "첫신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateTrans)
                {
                    logMsg += "전환신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateOver)
                {
                    logMsg += "돌파신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateLiquid)
                {
                    logMsg += "청산신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateCorrect)
                {
                    logMsg += "수정신호";
                }
                else
                {
                    logMsg += "상태없음";
                }
            }
            logMsg += ", 일일진폭 : " + (m_ETHighLowSignalManager.DayHigh - m_ETHighLowSignalManager.DayLow).ToString("F2");
            logMsg += ", 일일종가진폭 : " + (m_ETHighLowSignalManager.DayCloseMax - m_ETHighLowSignalManager.DayCloseMin).ToString("F2");

            logMsg += ", 신파진폭 : " + (m_SignalHighLowInfo.HighY - m_SignalHighLowInfo.LowY).ToString("F2");
            logMsg += ", 신파종가진폭 : " + (m_SignalHighLowInfo.CloseMax - m_SignalHighLowInfo.CloseMin).ToString("F2");
            if (m_CurWaveRegression != null)
            {
                logMsg += ", 현재평균파높이 : " + CurWaveRegression.Height().ToString("F2");
            }
            if (m_LastSignalRegression != null)
            {
                logMsg += ", 현재신호파높이 : " + LastSignalRegression.Height().ToString("F2");
            }
            if (m_CurWave != null)
            {
                logMsg += ", 파동 StartX : " + m_CurWave.StartX.ToString();
                logMsg += ", 파동 StartY : " + m_CurWave.StartY.ToString("F2");
                logMsg += ", 파동 EndX : " + m_CurWave.EndX.ToString();
                logMsg += ", 파동 EndY : " + m_CurWave.EndY.ToString("F2");
                logMsg += ", 파동 방향 : ";
                if (m_CurWave.Slope == GlobalVar.PriceUp)
                    logMsg += "상승";
                else if (m_CurWave.Slope == GlobalVar.PriceDown)
                    logMsg += "하락";
                else
                    logMsg += "방향없음";

                logMsg += ", 파동 최고가 : " + m_CurWave.HighY.ToString("F2");
                logMsg += ", 파동 최저가 : " + m_CurWave.LowY.ToString("F2");
                logMsg += ", 파동 종가최고가 : " + m_CurWave.CloseMax.ToString("F2");
                logMsg += ", 파동 종가최저가 : " + m_CurWave.CloseMin.ToString("F2");
            }

            logMsg += ", 일고가 : " + m_ETHighLowSignalManager.DayHigh.ToString("F2");
            logMsg += ", 일저가 : " + m_ETHighLowSignalManager.DayLow.ToString("F2");

            logMsg += ", 종고가 : " + m_ETHighLowSignalManager.DayCloseMax.ToString("F2");
            logMsg += ", 종저가 : " + m_ETHighLowSignalManager.DayCloseMin.ToString("F2");

            logMsg += ", 신호고가 : " + m_SignalHighLowInfo.HighY.ToString("F2");
            logMsg += ", 신호저가 : " + m_SignalHighLowInfo.LowY.ToString("F2");

            logMsg += ", 신호종고가 : " + m_SignalHighLowInfo.CloseMax.ToString("F2");
            logMsg += ", 신호종저가 : " + m_SignalHighLowInfo.CloseMin.ToString("F2");
            GlobalVar.WriteLog(logMsg);
        }

        public void WriteStateLog(int a_CurIndex, EasyTrader.Signal.PriceSignal a_Signal, string a_LogFileName)
        {
            DateTime now = DateTime.Now;
            if ((now.Second % 10) != 0)
                return;

            string logMsg = "시스템 상태 :: 인덱스 : " + a_CurIndex.ToString();
            logMsg += ", 시간 : " + GlobalVar.TimeToIntEx().ToString();
            //EasyTrader.Signal.PriceSignal a_Signal = GetLastSignal();
            if (a_Signal != null)
            {
                logMsg += ", 현재신호 : ";
                if (a_Signal.Type == GlobalVar.SignalNone)
                {
                    logMsg += "신호없음";
                }
                else if (a_Signal.Type == GlobalVar.SignalSell)
                {
                    logMsg += "매도";
                }
                else if (a_Signal.Type == GlobalVar.SignalBuy)
                {
                    logMsg += "매수";
                }
                else
                {
                    logMsg += "알수없음";
                }

                logMsg += ", 신호상태 : ";
                if (a_Signal.SignalState == GlobalVar.SignalStateFirst)
                {
                    logMsg += "첫신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateTrans)
                {
                    logMsg += "전환신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateOver)
                {
                    logMsg += "돌파신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateLiquid)
                {
                    logMsg += "청산신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateCorrect)
                {
                    logMsg += "수정신호";
                }
                else
                {
                    logMsg += "상태없음";
                }
            }
            logMsg += ", 일일진폭 : " + (m_ETHighLowSignalManager.DayHigh - m_ETHighLowSignalManager.DayLow).ToString("F2");
            logMsg += ", 일일종가진폭 : " + (m_ETHighLowSignalManager.DayCloseMax - m_ETHighLowSignalManager.DayCloseMin).ToString("F2");

            logMsg += ", 신파진폭 : " + (m_SignalHighLowInfo.HighY - m_SignalHighLowInfo.LowY).ToString("F2");
            logMsg += ", 신파종가진폭 : " + (m_SignalHighLowInfo.CloseMax - m_SignalHighLowInfo.CloseMin).ToString("F2");
            if (m_CurWaveRegression != null)
            {
                logMsg += ", 현재평균파높이 : " + CurWaveRegression.Height().ToString("F2");
            }
            if (m_LastSignalRegression != null)
            {
                logMsg += ", 현재신호파높이 : " + LastSignalRegression.Height().ToString("F2");
            }
            if (m_CurWave != null)
            {
                logMsg += ", 파동 StartX : " + m_CurWave.StartX.ToString();
                logMsg += ", 파동 StartY : " + m_CurWave.StartY.ToString("F2");
                logMsg += ", 파동 EndX : " + m_CurWave.EndX.ToString();
                logMsg += ", 파동 EndY : " + m_CurWave.EndY.ToString("F2");
                logMsg += ", 파동 방향 : ";
                if (m_CurWave.Slope == GlobalVar.PriceUp)
                    logMsg += "상승";
                else if (m_CurWave.Slope == GlobalVar.PriceDown)
                    logMsg += "하락";
                else
                    logMsg += "방향없음";

                logMsg += ", 파동 최고가 : " + m_CurWave.HighY.ToString("F2");
                logMsg += ", 파동 최저가 : " + m_CurWave.LowY.ToString("F2");
                logMsg += ", 파동 종가최고가 : " + m_CurWave.CloseMax.ToString("F2");
                logMsg += ", 파동 종가최저가 : " + m_CurWave.CloseMin.ToString("F2");
            }

            logMsg += ", 일고가 : " + m_ETHighLowSignalManager.DayHigh.ToString("F2");
            logMsg += ", 일저가 : " + m_ETHighLowSignalManager.DayLow.ToString("F2");

            logMsg += ", 종고가 : " + m_ETHighLowSignalManager.DayCloseMax.ToString("F2");
            logMsg += ", 종저가 : " + m_ETHighLowSignalManager.DayCloseMin.ToString("F2");

            logMsg += ", 신호고가 : " + m_SignalHighLowInfo.HighY.ToString("F2");
            logMsg += ", 신호저가 : " + m_SignalHighLowInfo.LowY.ToString("F2");

            logMsg += ", 신호종고가 : " + m_SignalHighLowInfo.CloseMax.ToString("F2");
            logMsg += ", 신호종저가 : " + m_SignalHighLowInfo.CloseMin.ToString("F2");
            GlobalVar.WriteLogWithFileName(logMsg, a_LogFileName);
        }

        private void WriteStateLog(int a_CurIndex)
        {
            DateTime now = DateTime.Now;
            if ((now.Second % 10) != 0)
                return;

            string logMsg = "시스템 상태 :: 인덱스 : " + a_CurIndex.ToString();
            logMsg += ", 시간 : " + GlobalVar.TimeToIntEx().ToString();
            EasyTrader.Signal.PriceSignal a_Signal = GetLastSignal();
            if (a_Signal != null)
            {
                logMsg += ", 현재신호 : ";
                if (a_Signal.Type == GlobalVar.SignalNone)
                {
                    logMsg += "신호없음";
                }
                else if (a_Signal.Type == GlobalVar.SignalSell)
                {
                    logMsg += "매도";
                }
                else if (a_Signal.Type == GlobalVar.SignalBuy)
                {
                    logMsg += "매수";
                }
                else
                {
                    logMsg += "알수없음";
                }

                logMsg += ", 신호상태 : ";
                if (a_Signal.SignalState == GlobalVar.SignalStateFirst)
                {
                    logMsg += "첫신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateTrans)
                {
                    logMsg += "전환신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateOver)
                {
                    logMsg += "돌파신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateLiquid)
                {
                    logMsg += "청산신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateCorrect)
                {
                    logMsg += "수정신호";
                }
                else
                {
                    logMsg += "상태없음";
                }
            }
            logMsg += ", 일일진폭 : " + (m_ETHighLowSignalManager.DayHigh - m_ETHighLowSignalManager.DayLow).ToString("F2");
            logMsg += ", 일일종가진폭 : " + (m_ETHighLowSignalManager.DayCloseMax - m_ETHighLowSignalManager.DayCloseMin).ToString("F2");

            logMsg += ", 신파진폭 : " + (m_SignalHighLowInfo.HighY - m_SignalHighLowInfo.LowY).ToString("F2");
            logMsg += ", 신파종가진폭 : " + (m_SignalHighLowInfo.CloseMax - m_SignalHighLowInfo.CloseMin).ToString("F2");
            if (m_CurWaveRegression != null)
            {
                logMsg += ", 현재평균파높이 : " + CurWaveRegression.Height().ToString("F2");
            }
            if (m_LastSignalRegression != null)
            {
                logMsg += ", 현재신호파높이 : " + LastSignalRegression.Height().ToString("F2");
            }
            if (m_CurWave != null)
            {
                logMsg += ", 파동 StartX : " + m_CurWave.StartX.ToString();
                logMsg += ", 파동 StartY : " + m_CurWave.StartY.ToString("F2");
                logMsg += ", 파동 EndX : " + m_CurWave.EndX.ToString();
                logMsg += ", 파동 EndY : " + m_CurWave.EndY.ToString("F2");
                logMsg += ", 파동 방향 : ";
                if (m_CurWave.Slope == GlobalVar.PriceUp)
                    logMsg += "상승";
                else if (m_CurWave.Slope == GlobalVar.PriceDown)
                    logMsg += "하락";
                else
                    logMsg += "방향없음";

                logMsg += ", 파동 최고가 : " + m_CurWave.HighY.ToString("F2");
                logMsg += ", 파동 최저가 : " + m_CurWave.LowY.ToString("F2");
                logMsg += ", 파동 종가최고가 : " + m_CurWave.CloseMax.ToString("F2");
                logMsg += ", 파동 종가최저가 : " + m_CurWave.CloseMin.ToString("F2");
            }

            logMsg += ", 일고가 : " + m_ETHighLowSignalManager.DayHigh.ToString("F2");
            logMsg += ", 일저가 : " + m_ETHighLowSignalManager.DayLow.ToString("F2");

            logMsg += ", 종고가 : " + m_ETHighLowSignalManager.DayCloseMax.ToString("F2");
            logMsg += ", 종저가 : " + m_ETHighLowSignalManager.DayCloseMin.ToString("F2");

            logMsg += ", 신호고가 : " + m_SignalHighLowInfo.HighY.ToString("F2");
            logMsg += ", 신호저가 : " + m_SignalHighLowInfo.LowY.ToString("F2");

            logMsg += ", 신호종고가 : " + m_SignalHighLowInfo.CloseMax.ToString("F2");
            logMsg += ", 신호종저가 : " + m_SignalHighLowInfo.CloseMin.ToString("F2");
            GlobalVar.WriteLog(logMsg);
        }

        public void WriteErrorLog(int a_CurIndex, string a_Msg)
        {
            string logMsg = "시스템 상태 :: 인덱스 : " + a_CurIndex.ToString();
            logMsg += ", 오류내용 : " + a_Msg;
            logMsg += ", 시간 : " + GlobalVar.TimeToIntEx().ToString();
            EasyTrader.Signal.PriceSignal a_Signal = GetLastSignal();
            if (a_Signal != null)
            {
                logMsg += ", 현재신호 : ";
                if (a_Signal.Type == GlobalVar.SignalNone)
                {
                    logMsg += "신호없음";
                }
                else if (a_Signal.Type == GlobalVar.SignalSell)
                {
                    logMsg += "매도";
                }
                else if (a_Signal.Type == GlobalVar.SignalBuy)
                {
                    logMsg += "매수";
                }
                else
                {
                    logMsg += "알수없음";
                }

                logMsg += ", 신호상태 : ";
                if (a_Signal.SignalState == GlobalVar.SignalStateFirst)
                {
                    logMsg += "첫신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateTrans)
                {
                    logMsg += "전환신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateOver)
                {
                    logMsg += "돌파신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateLiquid)
                {
                    logMsg += "청산신호";
                }
                else if (a_Signal.SignalState == GlobalVar.SignalStateCorrect)
                {
                    logMsg += "수정신호";
                }
                else
                {
                    logMsg += "상태없음";
                }
            }
            logMsg += ", 일일진폭 : " + (m_ETHighLowSignalManager.DayHigh - m_ETHighLowSignalManager.DayLow).ToString("F2");
            logMsg += ", 일일종가진폭 : " + (m_ETHighLowSignalManager.DayCloseMax - m_ETHighLowSignalManager.DayCloseMin).ToString("F2");

            logMsg += ", 신파진폭 : " + (m_SignalHighLowInfo.HighY - m_SignalHighLowInfo.LowY).ToString("F2");
            logMsg += ", 신파종가진폭 : " + (m_SignalHighLowInfo.CloseMax - m_SignalHighLowInfo.CloseMin).ToString("F2");
            if (m_CurWave != null)
            {
                logMsg += ", 파동 StartX : " + m_CurWave.StartX.ToString();
                logMsg += ", 파동 StartY : " + m_CurWave.StartY.ToString("F2");
                logMsg += ", 파동 EndX : " + m_CurWave.EndX.ToString();
                logMsg += ", 파동 EndY : " + m_CurWave.EndY.ToString("F2");
                logMsg += ", 파동 방향 : ";
                if (m_CurWave.Slope == GlobalVar.PriceUp)
                    logMsg += "상승";
                else if (m_CurWave.Slope == GlobalVar.PriceDown)
                    logMsg += "하락";
                else
                    logMsg += "방향없음";

                logMsg += ", 파동 최고가 : " + m_CurWave.HighY.ToString("F2");
                logMsg += ", 파동 최저가 : " + m_CurWave.LowY.ToString("F2");
                logMsg += ", 파동 종가최고가 : " + m_CurWave.CloseMax.ToString("F2");
                logMsg += ", 파동 종가최저가 : " + m_CurWave.CloseMin.ToString("F2");
            }

            logMsg += ", 일고가 : " + m_ETHighLowSignalManager.DayHigh.ToString("F2");
            logMsg += ", 일저가 : " + m_ETHighLowSignalManager.DayLow.ToString("F2");

            logMsg += ", 종고가 : " + m_ETHighLowSignalManager.DayCloseMax.ToString("F2");
            logMsg += ", 종저가 : " + m_ETHighLowSignalManager.DayCloseMin.ToString("F2");

            logMsg += ", 신호고가 : " + m_SignalHighLowInfo.HighY.ToString("F2");
            logMsg += ", 신호저가 : " + m_SignalHighLowInfo.LowY.ToString("F2");

            logMsg += ", 신호종고가 : " + m_SignalHighLowInfo.CloseMax.ToString("F2");
            logMsg += ", 신호종저가 : " + m_SignalHighLowInfo.CloseMin.ToString("F2");
            GlobalVar.WriteLog(logMsg);
        }

        public void SetStateInfo(int a_CurIndex, int a_SignalVal, int a_SignalState)
        {
            int signalCount = m_PriceSignalList.Count;
            int signalTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
                signalTime = GlobalVar.DayIndexToTimeEx(a_CurIndex);
            else
            {
                signalTime = GlobalVar.TimeToIntEx();
            }
            if (signalCount <= 0)
            {
                m_CurSignal.Type = a_SignalVal;
                m_CurSignal.Time = signalTime;
                m_CurSignal.X = a_CurIndex;
                m_CurSignal.Y = m_CurVal;
                m_CurSignal.CurWaveStartX = m_CurWave.StartX;
                m_CurSignal.CurWaveStartY = m_CurWave.StartY;
                m_CurSignal.CurWaveEndX = m_CurWave.EndX;
                m_CurSignal.CurWaveEndY = m_CurWave.EndY;
                m_CurSignal.CurWaveSlope = m_CurWave.Slope;
                m_CurSignal.CurWaveCloseMax = m_CurWave.CloseMax;
                m_CurSignal.CurWaveCloseMin = m_CurWave.CloseMin;
                m_CurSignal.CurWaveHigh = m_CurWave.HighY;
                m_CurSignal.CurWaveLow = m_CurWave.LowY;
                m_CurSignal.DayMax = m_ETHighLowSignalManager.DayHigh;
                m_CurSignal.DayMin = m_ETHighLowSignalManager.DayLow;
                m_CurSignal.DayCloseMax = m_ETHighLowSignalManager.DayCloseMax;
                m_CurSignal.DayCloseMin = m_ETHighLowSignalManager.DayCloseMin;
                m_CurSignal.SignalMax = m_SignalHighLowInfo.HighY;
                m_CurSignal.SignalMin = m_SignalHighLowInfo.LowY;
                m_CurSignal.SignalCloseMax = m_SignalHighLowInfo.CloseMax;
                m_CurSignal.SignalCloseMin = m_SignalHighLowInfo.CloseMin;
                m_CurSignal.SignalState = a_SignalState;
                m_CurSignal.StateNumber = GlobalVar.SignalStateNone;
                m_CurSignal.WaveType = GlobalVar.WaveTypeNone;
                m_CurSignal.BuyDayHigh = m_BuyDayHigh;
                m_CurSignal.SellDayHigh = m_SellDayHigh;
                m_CurSignal.SignalBuyHeight = m_BuyHighLowInfo.BuyHigh - m_BuyHighLowInfo.BuyLow;
                m_CurSignal.SignalSellHeight = m_SellHighLowInfo.SellHigh - m_SellHighLowInfo.SellLow;
                m_CurSignal.HighX = m_SignalHighLowInfo.HighX;
                m_CurSignal.LowX = m_SignalHighLowInfo.LowX;
            }
            else
            {
                EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal();
                m_CurSignal.Type = a_SignalVal;
                m_CurSignal.Time = signalTime;
                m_CurSignal.X = a_CurIndex;
                m_CurSignal.Y = m_CurVal;
                m_CurSignal.CurWaveStartX = m_CurWave.StartX;
                m_CurSignal.CurWaveStartY = m_CurWave.StartY;
                m_CurSignal.CurWaveEndX = m_CurWave.EndX;
                m_CurSignal.CurWaveEndY = m_CurWave.EndY;
                m_CurSignal.CurWaveSlope = m_CurWave.Slope;
                m_CurSignal.CurWaveCloseMax = m_CurWave.CloseMax;
                m_CurSignal.CurWaveCloseMin = m_CurWave.CloseMin;
                m_CurSignal.CurWaveHigh = m_CurWave.HighY;
                m_CurSignal.CurWaveLow = m_CurWave.LowY;
                m_CurSignal.DayMax = m_ETHighLowSignalManager.DayHigh;
                m_CurSignal.DayMin = m_ETHighLowSignalManager.DayLow;
                m_CurSignal.DayCloseMax = m_ETHighLowSignalManager.DayCloseMax;
                m_CurSignal.DayCloseMin = m_ETHighLowSignalManager.DayCloseMin;
                m_CurSignal.SignalMax = m_SignalHighLowInfo.HighY;
                m_CurSignal.SignalMin = m_SignalHighLowInfo.LowY;
                m_CurSignal.SignalCloseMax = m_SignalHighLowInfo.CloseMax;
                m_CurSignal.SignalCloseMin = m_SignalHighLowInfo.CloseMin;
                m_CurSignal.SignalState = a_SignalState;
                m_CurSignal.StateNumber = lastSignal.SignalState;
                m_CurSignal.WaveType = GlobalVar.WaveTypeNone;
                m_CurSignal.BuyDayHigh = m_BuyDayHigh;
                m_CurSignal.SellDayHigh = m_SellDayHigh;
                m_CurSignal.SignalBuyHeight = m_BuyHighLowInfo.BuyHigh - m_BuyHighLowInfo.BuyLow;
                m_CurSignal.SignalSellHeight = m_SellHighLowInfo.SellHigh - m_SellHighLowInfo.SellLow;
                m_CurSignal.HighX = m_SignalHighLowInfo.HighX;
                m_CurSignal.LowX = m_SignalHighLowInfo.LowX;
            }
        }


        public void SetStateInfo(int a_CurIndex, int a_SignalVal, int a_SignalState, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            if (m_CurWave == null)
                return;

            int signalTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
                signalTime = GlobalVar.DayIndexToTimeEx(a_CurIndex);
            else
            {
                signalTime = GlobalVar.TimeToIntEx();
            }
            a_CurSignal.Type = a_SignalVal;
            a_CurSignal.Time = signalTime;
            a_CurSignal.X = a_CurIndex;
            a_CurSignal.Y = m_CurVal;
            a_CurSignal.CurWaveStartX = m_CurWave.StartX;
            a_CurSignal.CurWaveStartY = m_CurWave.StartY;
            a_CurSignal.CurWaveEndX = m_CurWave.EndX;
            a_CurSignal.CurWaveEndY = m_CurWave.EndY;
            a_CurSignal.CurWaveSlope = m_CurWave.Slope;
            a_CurSignal.CurWaveCloseMax = m_CurWave.CloseMax;
            a_CurSignal.CurWaveCloseMin = m_CurWave.CloseMin;
            a_CurSignal.CurWaveHigh = m_CurWave.HighY;
            a_CurSignal.CurWaveLow = m_CurWave.LowY;
            a_CurSignal.DayMax = m_ETHighLowSignalManager.DayHigh;
            a_CurSignal.DayMin = m_ETHighLowSignalManager.DayLow;
            a_CurSignal.DayCloseMax = m_ETHighLowSignalManager.DayCloseMax;
            a_CurSignal.DayCloseMin = m_ETHighLowSignalManager.DayCloseMin;
            a_CurSignal.SignalMax = m_SignalHighLowInfo.HighY;
            a_CurSignal.SignalMin = m_SignalHighLowInfo.LowY;
            a_CurSignal.SignalCloseMax = m_SignalHighLowInfo.CloseMax;
            a_CurSignal.SignalCloseMin = m_SignalHighLowInfo.CloseMin;
            a_CurSignal.SignalState = a_SignalState;
            a_CurSignal.StateNumber = GlobalVar.SignalStateNone;
            a_CurSignal.WaveType = GlobalVar.WaveTypeNone;
            a_CurSignal.BuyDayHigh = m_BuyDayHigh;
            a_CurSignal.SellDayHigh = m_SellDayHigh;
            a_CurSignal.SignalBuyHeight = m_BuyHighLowInfo.BuyHigh - m_BuyHighLowInfo.BuyLow;
            a_CurSignal.SignalSellHeight = m_SellHighLowInfo.SellHigh - m_SellHighLowInfo.SellLow;
            a_CurSignal.HighX = m_SignalHighLowInfo.HighX;
            a_CurSignal.LowX = m_SignalHighLowInfo.LowX;
        }

        
        public void SetSignalInfo(int a_StateNumber, int a_SignalVal, int a_SignalState, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            if (m_CurWave == null)
                return;

            int signalTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
            {
                signalTime = GlobalVar.DayIndexToTimeEx(m_CurIndex);
                
            }
            else
            {
                signalTime = GlobalVar.TimeToIntEx();
            }

            a_CurSignal.OpTime = GlobalVar.DayIndexToTime(m_CurIndex);
            a_CurSignal.Type = a_SignalVal;
            a_CurSignal.Time = signalTime;
            a_CurSignal.X = m_CurIndex;
            a_CurSignal.Y = m_CurVal;
            a_CurSignal.CurWaveStartX = m_CurWave.StartX;
            a_CurSignal.CurWaveStartY = m_CurWave.StartY;
            a_CurSignal.CurWaveEndX = m_CurWave.EndX;
            a_CurSignal.CurWaveEndY = m_CurWave.EndY;
            a_CurSignal.CurWaveSlope = m_CurWave.Slope;
            a_CurSignal.CurWaveCloseMax = m_CurWave.CloseMax;
            a_CurSignal.CurWaveCloseMin = m_CurWave.CloseMin;
            a_CurSignal.CurWaveHigh = m_CurWave.HighY;
            a_CurSignal.CurWaveLow = m_CurWave.LowY;
            a_CurSignal.DayMax = m_ETHighLowSignalManager.DayHigh;
            a_CurSignal.DayMin = m_ETHighLowSignalManager.DayLow;
            a_CurSignal.DayCloseMax = m_ETHighLowSignalManager.DayCloseMax;
            a_CurSignal.DayCloseMin = m_ETHighLowSignalManager.DayCloseMin;
            a_CurSignal.SignalMax = m_SignalHighLowInfo.HighY;
            a_CurSignal.SignalMin = m_SignalHighLowInfo.LowY;
            a_CurSignal.SignalCloseMax = m_SignalHighLowInfo.CloseMax;
            a_CurSignal.SignalCloseMin = m_SignalHighLowInfo.CloseMin;
            a_CurSignal.SignalState = a_SignalState;
            a_CurSignal.StateNumber = a_StateNumber;
            a_CurSignal.WaveType = GlobalVar.WaveTypeNone;
            a_CurSignal.BuyDayHigh = m_BuyDayHigh;
            a_CurSignal.SellDayHigh = m_SellDayHigh;
            a_CurSignal.SignalBuyHeight = m_BuyHighLowInfo.BuyHigh - m_BuyHighLowInfo.BuyLow;
            a_CurSignal.SignalSellHeight = m_SellHighLowInfo.SellHigh - m_SellHighLowInfo.SellLow;
            a_CurSignal.HighX = m_SignalHighLowInfo.HighX;
            a_CurSignal.LowX = m_SignalHighLowInfo.LowX;
            a_CurSignal.CallDayHigh = m_CallDayHigh;
            a_CurSignal.PutDayHigh = m_PutDayHigh;
        }

        public void SetSignalInfo(int a_CurIndex, int a_StateNumber, int a_SignalVal, int a_SignalState, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            if (m_CurWave == null)
                return;

            int signalTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
                signalTime = GlobalVar.DayIndexToTimeEx(a_CurIndex);
            else
            {
                signalTime = GlobalVar.TimeToIntEx();
            }
            a_CurSignal.Type = a_SignalVal;
            a_CurSignal.Time = signalTime;
            a_CurSignal.X = a_CurIndex;
            a_CurSignal.Y = m_CurVal;
            a_CurSignal.CurWaveStartX = m_CurWave.StartX;
            a_CurSignal.CurWaveStartY = m_CurWave.StartY;
            a_CurSignal.CurWaveEndX = m_CurWave.EndX;
            a_CurSignal.CurWaveEndY = m_CurWave.EndY;
            a_CurSignal.CurWaveSlope = m_CurWave.Slope;
            a_CurSignal.CurWaveCloseMax = m_CurWave.CloseMax;
            a_CurSignal.CurWaveCloseMin = m_CurWave.CloseMin;
            a_CurSignal.CurWaveHigh = m_CurWave.HighY;
            a_CurSignal.CurWaveLow = m_CurWave.LowY;
            a_CurSignal.DayMax = m_ETHighLowSignalManager.DayHigh;
            a_CurSignal.DayMin = m_ETHighLowSignalManager.DayLow;
            a_CurSignal.DayCloseMax = m_ETHighLowSignalManager.DayCloseMax;
            a_CurSignal.DayCloseMin = m_ETHighLowSignalManager.DayCloseMin;
            a_CurSignal.SignalMax = m_SignalHighLowInfo.HighY;
            a_CurSignal.SignalMin = m_SignalHighLowInfo.LowY;
            a_CurSignal.SignalCloseMax = m_SignalHighLowInfo.CloseMax;
            a_CurSignal.SignalCloseMin = m_SignalHighLowInfo.CloseMin;
            a_CurSignal.SignalState = a_SignalState;
            a_CurSignal.StateNumber = a_StateNumber;
            a_CurSignal.WaveType = GlobalVar.WaveTypeNone;
            a_CurSignal.BuyDayHigh = m_BuyDayHigh;
            a_CurSignal.SellDayHigh = m_SellDayHigh;
            a_CurSignal.SignalBuyHeight = m_BuyHighLowInfo.BuyHigh - m_BuyHighLowInfo.BuyLow;
            a_CurSignal.SignalSellHeight = m_SellHighLowInfo.SellHigh - m_SellHighLowInfo.SellLow;
            a_CurSignal.HighX = m_SignalHighLowInfo.HighX;
            a_CurSignal.LowX = m_SignalHighLowInfo.LowX;
            a_CurSignal.CallDayHigh = m_CallDayHigh;
            a_CurSignal.PutDayHigh = m_PutDayHigh;
        }

        public void SetStateInfo(int a_CurIndex, int a_SignalVal, int a_SignalState, int a_WaveType)
        {
            int signalCount = m_PriceSignalList.Count;
            int signalTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
                signalTime = GlobalVar.DayIndexToTimeEx(a_CurIndex);
            else
            {
                signalTime = GlobalVar.TimeToIntEx();
            }
            if (signalCount <= 0)
            {
                m_CurSignal.Type = a_SignalVal;
                m_CurSignal.Time = signalTime;
                m_CurSignal.X = a_CurIndex;
                m_CurSignal.Y = m_CurVal;
                m_CurSignal.CurWaveStartX = m_CurWave.StartX;
                m_CurSignal.CurWaveStartY = m_CurWave.StartY;
                m_CurSignal.CurWaveEndX = m_CurWave.EndX;
                m_CurSignal.CurWaveEndY = m_CurWave.EndY;
                m_CurSignal.CurWaveSlope = m_CurWave.Slope;
                m_CurSignal.CurWaveCloseMax = m_CurWave.CloseMax;
                m_CurSignal.CurWaveCloseMin = m_CurWave.CloseMin;
                m_CurSignal.CurWaveHigh = m_CurWave.HighY;
                m_CurSignal.CurWaveLow = m_CurWave.LowY;
                m_CurSignal.DayMax = m_ETHighLowSignalManager.DayHigh;
                m_CurSignal.DayMin = m_ETHighLowSignalManager.DayLow;
                m_CurSignal.DayCloseMax = m_ETHighLowSignalManager.DayCloseMax;
                m_CurSignal.DayCloseMin = m_ETHighLowSignalManager.DayCloseMin;
                m_CurSignal.SignalMax = m_SignalHighLowInfo.HighY;
                m_CurSignal.SignalMin = m_SignalHighLowInfo.LowY;
                m_CurSignal.SignalCloseMax = m_SignalHighLowInfo.CloseMax;
                m_CurSignal.SignalCloseMin = m_SignalHighLowInfo.CloseMin;
                m_CurSignal.SignalState = a_SignalState;
                m_CurSignal.StateNumber = GlobalVar.SignalStateNone;
                m_CurSignal.WaveType = a_WaveType;
                m_CurSignal.BuyDayHigh = m_BuyDayHigh;
                m_CurSignal.SellDayHigh = m_SellDayHigh;
                m_CurSignal.SignalBuyHeight = m_BuyHighLowInfo.BuyHigh - m_BuyHighLowInfo.BuyLow;
                m_CurSignal.SignalSellHeight = m_SellHighLowInfo.SellHigh - m_SellHighLowInfo.SellLow;
            }
            else
            {
                EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal();
                m_CurSignal.Type = a_SignalVal;
                m_CurSignal.Time = signalTime;
                m_CurSignal.X = a_CurIndex;
                m_CurSignal.Y = m_CurVal;
                m_CurSignal.CurWaveStartX = m_CurWave.StartX;
                m_CurSignal.CurWaveStartY = m_CurWave.StartY;
                m_CurSignal.CurWaveEndX = m_CurWave.EndX;
                m_CurSignal.CurWaveEndY = m_CurWave.EndY;
                m_CurSignal.CurWaveSlope = m_CurWave.Slope;
                m_CurSignal.CurWaveCloseMax = m_CurWave.CloseMax;
                m_CurSignal.CurWaveCloseMin = m_CurWave.CloseMin;
                m_CurSignal.CurWaveHigh = m_CurWave.HighY;
                m_CurSignal.CurWaveLow = m_CurWave.LowY;
                m_CurSignal.DayMax = m_ETHighLowSignalManager.DayHigh;
                m_CurSignal.DayMin = m_ETHighLowSignalManager.DayLow;
                m_CurSignal.DayCloseMax = m_ETHighLowSignalManager.DayCloseMax;
                m_CurSignal.DayCloseMin = m_ETHighLowSignalManager.DayCloseMin;
                m_CurSignal.SignalMax = m_SignalHighLowInfo.HighY;
                m_CurSignal.SignalMin = m_SignalHighLowInfo.LowY;
                m_CurSignal.SignalCloseMax = m_SignalHighLowInfo.CloseMax;
                m_CurSignal.SignalCloseMin = m_SignalHighLowInfo.CloseMin;
                m_CurSignal.SignalState = a_SignalState;
                m_CurSignal.StateNumber = lastSignal.SignalState;
                m_CurSignal.WaveType = a_WaveType;
                m_CurSignal.BuyDayHigh = m_BuyDayHigh;
                m_CurSignal.SellDayHigh = m_SellDayHigh;
                m_CurSignal.SignalBuyHeight = m_BuyHighLowInfo.BuyHigh - m_BuyHighLowInfo.BuyLow;
                m_CurSignal.SignalSellHeight = m_SellHighLowInfo.SellHigh - m_SellHighLowInfo.SellLow;
            }
        }
#region  Hoge Variables
        private ForecastingInfo m_BuyReg = new ForecastingInfo();
        private ForecastingInfo m_SellReg = new ForecastingInfo();
        private EasyTrader.Wave.PriceWave m_CurBuyWave = null;
        private EasyTrader.Wave.PriceWave m_CurSellWave = null;
        private int m_BuyDayHigh = 0;
        public int BuyDayHigh
        {
            get { return m_BuyDayHigh; }
            set { m_BuyDayHigh = value; }
        }
        private int m_SellDayHigh = 0;
        public int SellDayHigh
        {
            get { return m_SellDayHigh; }
            set { m_SellDayHigh = value; }
        }


        private EasyTrader.Signal.HighLowInfo m_BuyHighLowInfo = new EasyTrader.Signal.HighLowInfo();
        private EasyTrader.Signal.HighLowInfo m_SellHighLowInfo = new EasyTrader.Signal.HighLowInfo();
        private double DeltaHogaBuySell = 0; // 호가 건수 차이
        private double DeltaHogaBidsAsks = 0; // 호가 잔량 차이
        private int HighHogaBuySell = 0; // 상위쪽 호가 건수
        private int HighHogaBidsAsks = 0; // 상위쪽 호가 잔량
        private double HighOptionPerson = 0; // 상위 개인 옵션 금액
        private PriceSignalList m_HogaTransSignalList = new PriceSignalList();
        private PriceSignalList m_HogaLiquidSignalList = new PriceSignalList();
#endregion

#region Option Variables
        private int m_CallDayHigh = 0;
        public int CallDayHigh
        {
            get { return m_CallDayHigh; }
            set { m_CallDayHigh = value; }
        }
        
        private int m_PutDayHigh = 0;
        public int PutDayHigh
        {
            get { return m_PutDayHigh; }
            set { m_PutDayHigh = value; }
        }
        

#endregion
        // 신호 파동의 목록을 놓아 놓는다.
        private PriceWaveList m_SignalWaveList = new PriceWaveList();
        public PriceWaveList SignalWaveList
        {
            get { return m_SignalWaveList; }
            set { m_SignalWaveList = value; }
        }

        private double m_TotalProgressVal = 0.0;
        public double TotalProgressVal
        {
            get { return m_TotalProgressVal; }
            set { m_TotalProgressVal = value; }
        }

        private ForecastingInfo m_CurWaveForeInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo CurWaveForeInfo
        {
            get { return m_CurWaveForeInfo; }
            set { m_CurWaveForeInfo = value; }
        }

        private ForecastingInfo m_PureForeInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo PureForeInfo
        {
            get { return m_PureForeInfo; }
            set { m_PureForeInfo = value; }
        }
        

        private ForecastingInfo m_FutOptPriceInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo FutOptPriceInfo
        {
            get { return m_FutOptPriceInfo; }
            set { m_FutOptPriceInfo = value; }
        }
        private ForecastingInfo m_HogaBuyInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo HogaBuyInfo
        {
            get { return m_HogaBuyInfo; }
            set { m_HogaBuyInfo = value; }
        }
        private ForecastingInfo m_HogaSellInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo HogaSellInfo
        {
            get { return m_HogaSellInfo; }
            set { m_HogaSellInfo = value; }
        }
        private ForecastingInfo m_HogaBidsInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo HogaBidsInfo
        {
            get { return m_HogaBidsInfo; }
            set { m_HogaBidsInfo = value; }
        }
        private ForecastingInfo m_HogaAsksInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo HogaAsksInfo
        {
            get { return m_HogaAsksInfo; }
            set { m_HogaAsksInfo = value; }
        }
        private ForecastingInfo m_KospiPersonInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo KospiPersonInfo
        {
            get { return m_KospiPersonInfo; }
            set { m_KospiPersonInfo = value; }
        }
        private ForecastingInfo m_KospiOrganInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo KospiOrganInfo
        {
            get { return m_KospiOrganInfo; }
            set { m_KospiOrganInfo = value; }
        }
        private ForecastingInfo m_KospiForeignInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo KospiForeignInfo
        {
            get { return m_KospiForeignInfo; }
            set { m_KospiForeignInfo = value; }
        }
        private ForecastingInfo m_FutureForeignInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo FutureForeignInfo
        {
            get { return m_FutureForeignInfo; }
            set { m_FutureForeignInfo = value; }
        }
        private ForecastingInfo m_CallPersonInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo CallPersonInfo
        {
            get { return m_CallPersonInfo; }
            set { m_CallPersonInfo = value; }
        }
        private ForecastingInfo m_PutPersonInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo PutPersonInfo
        {
            get { return m_PutPersonInfo; }
            set { m_PutPersonInfo = value; }
        }
        private ForecastingInfo m_ProgramInfo = new ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo ProgramInfo
        {
            get { return m_ProgramInfo; }
            set { m_ProgramInfo = value; }
        }

        private double m_CurVal = 0.0;
        public double CurVal
        {
            get { return m_CurVal; }
            set { m_CurVal = value; }
        }

        private EasyTrader.Wave.PriceWave m_CurWave = null;
        public EasyTrader.Wave.PriceWave CurWave
        {
            get { return m_CurWave; }
            set { m_CurWave = value; }
        }
        private EasyTrader.Wave.PriceWave m_PreWave = null;

        private int m_TotalBuySquare = 0;
        public int TotalBuySquare
        {
            get { return m_TotalBuySquare; }
            set { m_TotalBuySquare = value; }
        }
        private int m_TotalSellSquare = 0;
        public int TotalSellSquare
        {
            get { return m_TotalSellSquare; }
            set { m_TotalSellSquare = value; }
        }

        private int m_TotalHogaSquare = 0;
        public int TotalHogaSquare
        {
            get { return m_TotalHogaSquare; }
            set { m_TotalHogaSquare = value; }
        }

        private int m_BuySquare = 0;
        public int BuySquare
        {
            get { return m_BuySquare; }
            set { m_BuySquare = value; }
        }
        private int m_SellSquare = 0;
        public int SellSquare
        {
            get { return m_SellSquare; }
            set { m_SellSquare = value; }
        }
        private int m_BuyTimeOcc = 0;
        public int BuyTimeOcc
        {
            get { return m_BuyTimeOcc; }
            set { m_BuyTimeOcc = value; }
        }
        private int m_SellTimeOcc = 0;
        public int SellTimeOcc
        {
            get { return m_SellTimeOcc; }
            set { m_SellTimeOcc = value; }
        }

        private int m_CallTimeOcc = 0;
        public int CallTimeOcc
        {
            get { return m_CallTimeOcc; }
            set { m_CallTimeOcc = value; }
        }
        private int m_PutTimeOcc = 0;
        public int PutTimeOcc
        {
            get { return m_PutTimeOcc; }
            set { m_PutTimeOcc = value; }
        }
        private int m_CallSquareOcc = 0;
        public int CallSquareOcc
        {
            get { return m_CallSquareOcc; }
            set { m_CallSquareOcc = value; }
        }
        private int m_PutSquareOcc = 0;
        public int PutSquareOcc
        {
            get { return m_PutSquareOcc; }
            set { m_PutSquareOcc = value; }
        }
        private int m_CallPutTotalSquareOcc = 0;
        public int CallPutTotalSquareOcc
        {
            get { return m_CallPutTotalSquareOcc; }
            set { m_CallPutTotalSquareOcc = value; }
        }
        private double m_TotalSignal = 0.0;
        public double TotalSignal
        {
            get { return m_TotalSignal; }
            set { m_TotalSignal = value; }
        }
        private double m_WaveSignal = 0.0;
        public double WaveSignal
        {
            get { return m_WaveSignal; }
            set { m_WaveSignal = value; }
        }
        private double m_ForeSignal = 0.0;
        public double ForeSignal
        {
            get { return m_ForeSignal; }
            set { m_ForeSignal = value; }
        }
        private double m_BuySellSignal = 0.0;
        public double BuySellSignal
        {
            get { return m_BuySellSignal; }
            set { m_BuySellSignal = value; }
        }
        private double m_BidsAsksSignal = 0.0;
        public double BidsAsksSignal
        {
            get { return m_BidsAsksSignal; }
            set { m_BidsAsksSignal = value; }
        }
        private double m_OrganPersonKospiSignal = 0.0;
        public double OrganPersonKospiSignal
        {
            get { return m_OrganPersonKospiSignal; }
            set { m_OrganPersonKospiSignal = value; }
        }
        private double m_ForeignPersonKospiSignal = 0.0;
        public double ForeignPersonKospiSignal
        {
            get { return m_ForeignPersonKospiSignal; }
            set { m_ForeignPersonKospiSignal = value; }
        }
        private double m_OptionCallPutSignal = 0.0;
        public double OptionCallPutSignal
        {
            get { return m_OptionCallPutSignal; }
            set { m_OptionCallPutSignal = value; }
        }
        private double m_ProgramSignal = 0.0;
        public double ProgramSignal
        {
            get { return m_ProgramSignal; }
            set { m_ProgramSignal = value; }
        }
        private double m_FutureSignal = 0.0;
        public double FutureSignal
        {
            get { return m_FutureSignal; }
            set { m_FutureSignal = value; }
        }

        private double m_HighLowSignal = 0.0;
        public double HighLowSignal
        {
            get { return m_HighLowSignal; }
            set { m_HighLowSignal = value; }
        }

        private double m_WorldSignal = 0.0;
        public double WorldSignal
        {
            get { return m_WorldSignal; }
            set { m_WorldSignal = value; }
        }
        

        private EasyTrader.Signal.WaveSignalManager m_ETWaveSignalManager = new EasyTrader.Signal.WaveSignalManager();
        public EasyTrader.Signal.WaveSignalManager ETWaveSignalManager
        {
            get { return m_ETWaveSignalManager; }
            set { m_ETWaveSignalManager = value; }
        }
        private EasyTrader.Signal.HogaSignalManager m_ETHogaSignalManager = new EasyTrader.Signal.HogaSignalManager();
        public EasyTrader.Signal.HogaSignalManager ETHogaSignalManager
        {
            get { return m_ETHogaSignalManager; }
            set { m_ETHogaSignalManager = value; }
        }
        private EasyTrader.Signal.BarSignalManager m_ETBarSignalManager = new EasyTrader.Signal.BarSignalManager();
        public EasyTrader.Signal.BarSignalManager ETBarSignalManager
        {
            get { return m_ETBarSignalManager; }
            set { m_ETBarSignalManager = value; }
        }
        private EasyTrader.Signal.SubjectSignalManager m_ETSubjectSignalManager = new EasyTrader.Signal.SubjectSignalManager();
        public EasyTrader.Signal.SubjectSignalManager ETSubjectSignalManager
        {
            get { return m_ETSubjectSignalManager; }
            set { m_ETSubjectSignalManager = value; }
        }

        private EasyTrader.Signal.HighLowSignalManager m_ETHighLowSignalManager = new EasyTrader.Signal.HighLowSignalManager();
        public EasyTrader.Signal.HighLowSignalManager ETHighLowSignalManager
        {
            get { return m_ETHighLowSignalManager; }
            set { m_ETHighLowSignalManager = value; }
        }

        private EasyTrader.Order.OrderManager m_ETOrderManager = null;
        public EasyTrader.Order.OrderManager ETOrderManager
        {
            get { return m_ETOrderManager; }
            set { m_ETOrderManager = value; }
        }

        public TotalSignalManager()
        {
            ;
        }

        private double m_WaveHighZoneVal = 0.0;
        public double WaveHighZoneVal
        {
            get { return m_WaveHighZoneVal; }
            set { m_WaveHighZoneVal = value; }
        }
        private double m_WaveLowZoneVal = 0.0;
        public double WaveLowZoneVal
        {
            get { return m_WaveLowZoneVal; }
            set { m_WaveLowZoneVal = value; }
        }

        private double m_ReverseRatio = 0.0;

        // 기준파로 신호 금지 영역을 구한다.
        public void CalcHighLowZoneByWave(int a_CurIndex, EasyTrader.Wave.PriceWave a_Wave, double a_Percent)
        {
            if (a_Wave == null)
                return;

            if (a_Wave.StartX == 0 || a_Wave.EndX == 0 ||
                a_Wave.StartY == 0 || a_Wave.EndY == 0)
                return;
            double waveHeight = 0.0;
            double curVal = GetCurVal(a_CurIndex);
            if (a_Wave.Slope == GlobalVar.PriceDown)
            {
                double minVal = Math.Min(a_Wave.EndY, m_ETHighLowSignalManager.DayLow);
                waveHeight = Math.Abs(a_Wave.StartY - Math.Min(a_Wave.EndY, m_ETHighLowSignalManager.DayLow));
                m_WaveHighZoneVal = a_Wave.StartY - waveHeight * a_Percent;
                m_WaveLowZoneVal = a_Wave.EndY + waveHeight * a_Percent;
                double deltaPrice = Math.Abs(curVal - minVal);
                m_ReverseRatio = deltaPrice / waveHeight * 100;
            }
            else
            {
                double maxVal = Math.Max(a_Wave.EndY, m_ETHighLowSignalManager.DayHigh);
                waveHeight = Math.Abs(a_Wave.StartY - Math.Max(a_Wave.EndY, m_ETHighLowSignalManager.DayHigh));
                m_WaveHighZoneVal = a_Wave.EndY - waveHeight * a_Percent;
                m_WaveLowZoneVal = a_Wave.StartY + waveHeight * a_Percent;
                double deltaPrice = Math.Abs(curVal - maxVal);
                m_ReverseRatio = deltaPrice / waveHeight * 100;
            }

            GlobalVar.ReverseRatio = m_ReverseRatio;
        }

        public double GetCurVal(int a_CurIndex)
        {
            if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
            {
                EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutOptChartTable();

                if (curTable == null)
                    return 0.0;
                int rowCount = curTable.Rows.Count;
                if (rowCount == 0)
                    return 0.0;

                if (a_CurIndex > rowCount - 1)
                    a_CurIndex = rowCount - 1;
                DataRow row = curTable.Rows[a_CurIndex];
                double CurVal = Convert.ToDouble(row["종가"]);
                return CurVal;
            }
            else
            {
                EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutOptChartTable();

                if (curTable == null)
                    return 0.0;
                int rowCount = curTable.Rows.Count;
                if (rowCount == 0)
                    return 0.0;
                for (int i = rowCount - 1; i >= 0; i--)
                {
                    DataRow row = curTable.Rows[i];
                    double CurVal = Convert.ToDouble(row["종가"]);
                    if (CurVal != 0.0)
                        return CurVal;
                }
            }

            return 0.0;
        }

        public double GetCurHigh(int a_CurIndex)
        {
            if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
            {
                EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutOptChartTable();

                if (curTable == null)
                    return 0.0;
                int rowCount = curTable.Rows.Count;
                if (rowCount == 0)
                    return 0.0;

                if (a_CurIndex > rowCount - 1)
                    a_CurIndex = rowCount - 1;
                DataRow row = curTable.Rows[a_CurIndex];
                double CurVal = Convert.ToDouble(row["고가"]);
                return CurVal;
            }
            else
            {
                EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutOptChartTable();

                if (curTable == null)
                    return 0.0;
                int rowCount = curTable.Rows.Count;
                if (rowCount == 0)
                    return 0.0;
                for (int i = rowCount - 1; i >= 0; i--)
                {
                    DataRow row = curTable.Rows[i];
                    double CurVal = Convert.ToDouble(row["고가"]);
                    if (CurVal != 0.0)
                        return CurVal;
                }
            }

            return 0.0;
        }

        public double GetCurLow(int a_CurIndex)
        {
            if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
            {
                EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutOptChartTable();

                if (curTable == null)
                    return 0.0;
                int rowCount = curTable.Rows.Count;
                if (rowCount == 0)
                    return 0.0;

                if (a_CurIndex > rowCount - 1)
                    a_CurIndex = rowCount - 1;
                DataRow row = curTable.Rows[a_CurIndex];
                double CurVal = Convert.ToDouble(row["저가"]);
                return CurVal;
            }
            else
            {
                EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutOptChartTable();

                if (curTable == null)
                    return 0.0;
                int rowCount = curTable.Rows.Count;
                if (rowCount == 0)
                    return 0.0;
                for (int i = rowCount - 1; i >= 0; i--)
                {
                    DataRow row = curTable.Rows[i];
                    double CurVal = Convert.ToDouble(row["저가"]);
                    if (CurVal != 0.0)
                        return CurVal;
                }
            }

            return 0.0;
        }

        public double GetCurOpen(int a_CurIndex)
        {
            if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
            {
                EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutOptChartTable();

                if (curTable == null)
                    return 0.0;
                int rowCount = curTable.Rows.Count;
                if (rowCount == 0)
                    return 0.0;

                if (a_CurIndex > rowCount - 1)
                    a_CurIndex = rowCount - 1;
                DataRow row = curTable.Rows[a_CurIndex];
                double CurVal = Convert.ToDouble(row["시가"]);
                return CurVal;
            }
            else
            {
                EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutOptChartTable();

                if (curTable == null)
                    return 0.0;
                int rowCount = curTable.Rows.Count;
                if (rowCount == 0)
                    return 0.0;
                for (int i = rowCount - 1; i >= 0; i--)
                {
                    DataRow row = curTable.Rows[i];
                    double CurVal = Convert.ToDouble(row["시가"]);
                    if (CurVal != 0.0)
                        return CurVal;
                }
            }

            return 0.0;
        }

        private bool IsOptionPersonExtremeCase()
        {
            if (m_CallPersonInfo == null || m_PutPersonInfo == null)
                return false;
            double deltaCall = m_CallPersonInfo.EndY - m_CallPersonInfo.StartY;
            double deltaPut = m_PutPersonInfo.EndY - m_PutPersonInfo.StartY;
            if (deltaCall > 0 && deltaPut < 0 && m_CallPersonInfo.EndY > 0 && m_PutPersonInfo.EndY < 0)
                return true;
            if (deltaCall < 0 && deltaPut > 0 && m_CallPersonInfo.EndY < 0 && m_PutPersonInfo.EndY > 0)
                return true;

            return false;
        }
        // 기준파 상위, 하위 영역에 있는지 조사하여 결과를 돌려준다.
        public bool IsInWaveHighLowZone(int a_CurIndex)
        {
            double curvVal = GetCurVal(a_CurIndex);
            if (curvVal >= m_WaveHighZoneVal)
                return true;
            if (curvVal <= m_WaveLowZoneVal)
                return true;

            return false;
        }

        public double GetDayAmp()
        {
            double dayAmp = m_ETHighLowSignalManager.DayHigh - m_ETHighLowSignalManager.DayLow;
            return dayAmp;
        }

        public double GetDayHigh()
        {
            return m_ETHighLowSignalManager.DayHigh;
        }

        public double GetDayLow()
        {
            return m_ETHighLowSignalManager.DayLow;
        }
        // 장 시작시에 갭상승이나 하락 값을 구한다.
        public double GetTodayDailyDelta()
        {
            EasyTrader.DataSet.FutOptDailyTable table = m_EasyTraderDataSet.GetFutOptDailyTable();
            if (table == null)
                return 0.0;
            int rowCount = table.GetRowCount();
            if (rowCount < 2)
                return 0.0;
            DataRow curRow = table.Rows[rowCount - 1];
            object curDate = curRow["날짜"];
            int intDate = GlobalVar.DateToInt();
            if (intDate == Convert.ToInt32(curDate))
            {
                DataRow preRow = table.Rows[rowCount - 2];
                double curOpen = Convert.ToDouble(curRow["시가"]);
                double preClose = Convert.ToDouble(preRow["종가"]);
                GlobalVar.DailyGap = Math.Abs(curOpen - preClose);
            }
            else
                GlobalVar.DailyGap = 0.0;

            return GlobalVar.DailyGap;
        }

        private double GetPreDayDailyGap(EasyTrader.DataSet.ETDataTable a_CurTable)
        {
            if (a_CurTable == null)
                return 0.0;
            int rowCount = a_CurTable.GetRowCount();
            if (rowCount < 2)
                return 0.0;
            DataRow curRow = a_CurTable.Rows[rowCount - 1];
            object curDate = curRow["날짜"];
            int intDate = GlobalVar.DateToInt();
            double dailyGap = 0.0;
            if (intDate == Convert.ToInt32(curDate))
            {
                DataRow preRow = a_CurTable.Rows[rowCount - 2];
                double curOpen = Convert.ToDouble(curRow["시가"]);
                double preClose = Convert.ToDouble(preRow["종가"]);
                dailyGap = Math.Abs(curOpen - preClose);
            }
            
            return dailyGap;
        }

        public double GetTodayDailyGap()
        {
            if (m_EasyTraderDataSet == null)
                return 0.0;

            EasyTrader.DataSet.ETDataTable curTable = m_EasyTraderDataSet.GetFutOptDailyTable();
            if (curTable == null)
                return 0.0;
            return GetPreDayDailyGap(curTable);
        }

        public double GetTodayDailyDelta(EasyTrader.DataSet.ETDataTable a_CurTable)
        {
            if (a_CurTable == null)
                return 0.0;
            int rowCount = a_CurTable.GetRowCount();
            if (rowCount < 2)
                return 0.0;
            DataRow curRow = a_CurTable.Rows[rowCount - 1];
            object curDate = curRow["날짜"];
            int intDate = GlobalVar.DateToInt();
            double dailyGap = 0.0;
            //if (intDate == Convert.ToInt32(curDate))
            //{
            double curOpen = Convert.ToDouble(curRow["시가"]);
            double curClose = Convert.ToDouble(curRow["종가"]);
            dailyGap = (curClose - curOpen);
            //}
            //else
            //    GlobalVar.DailyGap = 0.0;

            return dailyGap;
        }

        // 이 함수는 해외 지수를 참조하여 매도 혹은 매수의 퍼센트를 구한다.
        public double GetWorldCurSignal()
        {
            EasyTrader.DataSet.ETDataTable curTable = null;
            double dailyGap = 0.0;
            double factCount = 0.0;
            double totalPercent = 0.0;
            curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.Tables["DowIndustry"];
            dailyGap = GetTodayDailyDelta(curTable);
            if (GlobalVar.DJIEnable == true && curTable != null && dailyGap != 0.0)
            {
                if (dailyGap > 0.0)
                    totalPercent += 100.0;
                else
                    totalPercent += -100.0;
                factCount++;
            }
            curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.Tables["SNP500"];
            dailyGap = GetTodayDailyDelta(curTable);
            if (GlobalVar.SNP500Enable == true && curTable != null && dailyGap != 0.0)
            {
                if (dailyGap > 0.0)
                    totalPercent += 100.0;
                else
                    totalPercent += -100.0;
                factCount++;
            }
            curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.Tables["NASDAQ"];
            dailyGap = GetTodayDailyDelta(curTable);
            if (GlobalVar.NASDAQEnable == true && curTable != null && dailyGap != 0.0)
            {
                if (dailyGap > 0.0)
                    totalPercent += 100.0;
                else
                    totalPercent += -100.0;
                factCount++;
            }
            curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.Tables["EnglandFTSE"];
            dailyGap = GetTodayDailyDelta(curTable);
            if (GlobalVar.FTSEEnable == true && curTable != null && dailyGap != 0.0)
            {
                if (dailyGap > 0.0)
                    totalPercent += 100.0;
                else
                    totalPercent += -100.0;
                factCount++;
            }
            curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.Tables["DeuchDAX"];
            dailyGap = GetTodayDailyDelta(curTable);
            if (GlobalVar.DAXEnable == true && curTable != null && dailyGap != 0.0)
            {
                if (dailyGap > 0.0)
                    totalPercent += 100.0;
                else
                    totalPercent += -100.0;
                factCount++;
            }
            curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.Tables["FranceCAC"];
            dailyGap = GetTodayDailyDelta(curTable);
            if (GlobalVar.CACEnable == true && curTable != null && dailyGap != 0.0)
            {
                if (dailyGap > 0.0)
                    totalPercent += 100.0;
                else
                    totalPercent += -100.0;
                factCount++;
            }
            if (factCount == 0)
                return 0.0;
            else
                return totalPercent / factCount;
        }

        private int GetSigSourceCount()
        {
            int fact = 0;
            if (GlobalVar.WaveEnable == true && m_WaveSignal != 0)
            {
                m_TotalSignal = m_WaveSignal;
                fact++;
            }
            if (GlobalVar.ForecastEnable == true && m_ForeSignal != 0)
            {
                m_TotalSignal += m_ForeSignal;
                fact++;
            }
            if (GlobalVar.HogaBuySellEnable == true && m_BuySellSignal != 0)
            {
                m_TotalSignal += m_BuySellSignal;
                fact++;
            }
            if (GlobalVar.HogaBidAskEnable == true && m_BidsAsksSignal != 0)
            {
                m_TotalSignal += m_BidsAsksSignal;
                fact++;
            }
            if (GlobalVar.KospiOrganPersonEnable == true && m_OrganPersonKospiSignal != 0)
            {
                m_TotalSignal += m_OrganPersonKospiSignal;
                fact++;
            }
            if (GlobalVar.KospiForeignPersonEnable == true && m_ForeignPersonKospiSignal != 0)
            {
                m_TotalSignal += m_ForeignPersonKospiSignal;
                fact++;
            }
            if (GlobalVar.OptionPersonCallPutEnable == true && m_OptionCallPutSignal != 0)
            {
                m_TotalSignal += m_OptionCallPutSignal;
                fact++;
            }
            if (GlobalVar.KospiProgramEnable == true && m_ProgramSignal != 0)
            {
                m_TotalSignal += m_ProgramSignal;
                fact++;
            }
            if (GlobalVar.FutureForeignEnable == true && m_FutureSignal != 0)
            {
                m_TotalSignal += m_FutureSignal;
                fact++;
            }
            if (GlobalVar.HighLowEnable == true && m_HighLowSignal != 0)
            {
                m_TotalSignal += m_HighLowSignal;
                fact++;
            }

            if (GlobalVar.WorldEnable == true && m_CurIndex < 10 && m_WorldSignal != 0)
            {
                m_TotalSignal += m_WorldSignal;
                fact++;
            }

            return fact;
        }

        private void UpdateAngleSysInvDiv()
        {
            //int dayIndex = GlobalVar.DayIndex();
            double deltaY = 0.0;
            double deltaX = 0.0;
            double radians = 0.0;
            double angle = 0.0;
            // 각 신호 주체별 방향을 탐색한다. 각도와 수렴발산을 확인한다.
            m_ETWaveSignalManager.GetForecastingInfo(m_FutOptPriceInfo, "종가", GlobalVar.RegressionType, m_CurIndex, GlobalVar.PriceReferenceRange, false);
            if (m_FutOptPriceInfo != null)
            {
                deltaY = (m_FutOptPriceInfo.EndY - m_FutOptPriceInfo.StartY) * GlobalVar.PricePerMin;
                deltaX = Math.Abs(m_FutOptPriceInfo.EndX - m_FutOptPriceInfo.StartX);
                radians = Math.Atan2(deltaY, deltaX);
                angle = radians * (180 / Math.PI);
                m_FutOptPriceInfo.Angle = angle;
            }
            m_ETHogaSignalManager.GetForecastingInfo(m_HogaBuyInfo, "매수총호가건수", GlobalVar.RegressionType, m_CurIndex, GlobalVar.BuySellBeginRefRange, false);
            if (m_HogaBuyInfo != null)
            {
                deltaY = (m_HogaBuyInfo.EndY - m_HogaBuyInfo.StartY);
                deltaX = (m_HogaBuyInfo.EndX - m_HogaBuyInfo.StartX) * GlobalVar.HogaBuySellPerMin;
                radians = Math.Atan2(deltaY, deltaX);
                angle = radians * (180 / Math.PI);
                m_HogaBuyInfo.Angle = angle;
            }
            m_ETHogaSignalManager.GetForecastingInfo(m_HogaSellInfo, "매도총호가건수", GlobalVar.RegressionType, m_CurIndex, GlobalVar.BuySellBeginRefRange, false);
            if (m_HogaSellInfo != null)
            {
                deltaY = (m_HogaSellInfo.EndY - m_HogaSellInfo.StartY);
                deltaX = (m_HogaSellInfo.EndX - m_HogaSellInfo.StartX) * GlobalVar.HogaBuySellPerMin;
                radians = Math.Atan2(deltaY, deltaX);
                angle = radians * (180 / Math.PI);
                m_HogaSellInfo.Angle = angle;
            }
            m_ETHogaSignalManager.GetForecastingInfo(m_HogaBidsInfo, "매수총호가수량", GlobalVar.RegressionType, m_CurIndex, GlobalVar.HogaReferenceRange, false);
            if (m_HogaBidsInfo != null)
            {
                deltaY = (m_HogaBidsInfo.EndY - m_HogaBidsInfo.StartY);
                deltaX = Math.Abs(m_HogaBidsInfo.EndX - m_HogaBidsInfo.StartX) * GlobalVar.HogaBidsAsksPerMin;
                radians = Math.Atan2(deltaY, deltaX);
                angle = radians * (180 / Math.PI);
                m_HogaBidsInfo.Angle = angle;
            }
            m_ETHogaSignalManager.GetForecastingInfo(m_HogaAsksInfo, "매도총호가수량", GlobalVar.RegressionType, m_CurIndex, GlobalVar.HogaReferenceRange, false);
            if (m_HogaAsksInfo != null)
            {
                deltaY = (m_HogaAsksInfo.EndY - m_HogaAsksInfo.StartY);
                deltaX = Math.Abs(m_HogaAsksInfo.EndX - m_HogaAsksInfo.StartX) * GlobalVar.HogaBidsAsksPerMin;
                radians = Math.Atan2(deltaY, deltaX);
                angle = radians * (180 / Math.PI);
                m_HogaAsksInfo.Angle = angle;
            }
            m_ETSubjectSignalManager.GetProgramForecastingInfo(m_ProgramInfo, "전체순매수금액", GlobalVar.RegressionType, m_CurIndex, GlobalVar.ReferenceRange);
            if (m_ProgramInfo != null)
            {
                deltaY = (m_ProgramInfo.EndY / 100.0 - m_ProgramInfo.StartY / 100.0);
                deltaX = Math.Abs(m_ProgramInfo.EndX - m_ProgramInfo.StartX) * GlobalVar.ProgramPerMin;
                radians = Math.Atan2(deltaY, deltaX);
                angle = radians * (180 / Math.PI);
                m_ProgramInfo.Angle = angle;
            }
            m_ETSubjectSignalManager.GetSubjectForecastingInfo(m_KospiPersonInfo, "코스피개인순매수", GlobalVar.RegressionType, m_CurIndex, GlobalVar.ReferenceRange);
            if (m_KospiPersonInfo != null)
            {
                deltaY = (m_KospiPersonInfo.EndY / 100.0 - m_KospiPersonInfo.StartY / 100.0);
                deltaX = Math.Abs(m_KospiPersonInfo.EndX - m_KospiPersonInfo.StartX) * GlobalVar.KospiPerMin;
                radians = Math.Atan2(deltaY, deltaX);
                angle = radians * (180 / Math.PI);
                m_KospiPersonInfo.Angle = angle;
            }
            m_ETSubjectSignalManager.GetSubjectForecastingInfo(m_KospiOrganInfo, "코스피기관계순매수", GlobalVar.RegressionType, m_CurIndex, GlobalVar.ReferenceRange);
            if (m_KospiOrganInfo != null)
            {
                deltaY = (m_KospiOrganInfo.EndY / 100.0 - m_KospiOrganInfo.StartY / 100.0);
                deltaX = Math.Abs(m_KospiOrganInfo.EndX - m_KospiOrganInfo.StartX) * GlobalVar.KospiPerMin;
                radians = Math.Atan2(deltaY, deltaX);
                angle = radians * (180 / Math.PI);
                m_KospiOrganInfo.Angle = angle;
            }
            m_ETSubjectSignalManager.GetSubjectForecastingInfo(m_KospiForeignInfo, "코스피외국인순매수", GlobalVar.RegressionType, m_CurIndex, GlobalVar.ReferenceRange);
            if (m_KospiForeignInfo != null)
            {
                deltaY = (m_KospiForeignInfo.EndY / 100.0 - m_KospiForeignInfo.StartY / 100.0);
                deltaX = Math.Abs(m_KospiForeignInfo.EndX - m_KospiForeignInfo.StartX) * GlobalVar.KospiPerMin;
                radians = Math.Atan2(deltaY, deltaX);
                angle = radians * (180 / Math.PI);
                m_KospiForeignInfo.Angle = angle;
            }
            m_ETSubjectSignalManager.GetSubjectForecastingInfo(m_FutureForeignInfo, "선물외국인순매수", GlobalVar.RegressionType, m_CurIndex, GlobalVar.ReferenceRange);
            if (m_FutureForeignInfo != null)
            {
                deltaY = (m_FutureForeignInfo.EndY / 100.0 - m_FutureForeignInfo.StartY / 100.0);
                deltaX = Math.Abs(m_FutureForeignInfo.EndX - m_FutureForeignInfo.StartX) * GlobalVar.FuturePerMin;
                radians = Math.Atan2(deltaY, deltaX);
                angle = radians * (180 / Math.PI);
                m_FutureForeignInfo.Angle = angle;
            }
            m_ETSubjectSignalManager.GetSubjectForecastingInfo(m_CallPersonInfo, "개인옵션콜순매수", GlobalVar.RegressionType, m_CurIndex, GlobalVar.ReferenceRange);
            if (m_CallPersonInfo != null)
            {
                deltaY = (m_CallPersonInfo.EndY / 100.0 - m_CallPersonInfo.StartY / 100.0);
                deltaX = Math.Abs(m_CallPersonInfo.EndX - m_CallPersonInfo.StartX) * GlobalVar.OptionPerMin;
                radians = Math.Atan2(deltaY, deltaX);
                angle = radians * (180 / Math.PI);
                m_CallPersonInfo.Angle = angle;
            }
            m_ETSubjectSignalManager.GetSubjectForecastingInfo(m_PutPersonInfo, "개인옵션풋순매수", GlobalVar.RegressionType, m_CurIndex, GlobalVar.ReferenceRange);
            if (m_KospiOrganInfo != null)
            {
                deltaY = (m_PutPersonInfo.EndY / 100.0 - m_PutPersonInfo.StartY / 100.0);
                deltaX = Math.Abs(m_PutPersonInfo.EndX - m_PutPersonInfo.StartX) * GlobalVar.OptionPerMin;
                radians = Math.Atan2(deltaY, deltaX);
                angle = radians * (180 / Math.PI);
                m_PutPersonInfo.Angle = angle;
            }
        }
        // 이 함수는 현재 관심대상인 모든 가격들의 동향을 갱신한다.
        public void UpdateAllPriceState()
        {
            if (m_ETWaveSignalManager == null || m_ETHogaSignalManager == null || m_ETSubjectSignalManager == null)
                return;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && GlobalVar.AllDataDownloaded == false)
                return;

            UpdateAngleSysInvDiv();


            //m_ETHogaSignalManager.EasyTraderDataSet = m_EasyTraderDataSet;
            // 호가 시스템에 활용한 가상 차트에 데이터를 부여한다.
            // 내부적으로 여기서 호가에 대한 이동평균값을 적용한다.
            
            // 개인 콜 풋 중 높은 값을 구해 온다.
            HighOptionPerson = m_ETSubjectSignalManager.GetHigherOptionVal(m_CurIndex);
            // 호가를 실제값으로 차이를 구한다.
            DeltaHogaBuySell = Math.Abs(m_HogaBuyInfo.PureEndY - m_HogaSellInfo.PureEndY);
            DeltaHogaBidsAsks = Math.Abs(m_HogaBidsInfo.PureEndY - m_HogaAsksInfo.PureEndY);
            HighHogaBuySell = m_ETHogaSignalManager.GetHigherBuySell(m_CurIndex);
            HighHogaBidsAsks = m_ETHogaSignalManager.GetHigherBidAsk(m_CurIndex);
            // 현재 값과 현재 진폭을 위해 실행 시켜 준다.
            m_ETHighLowSignalManager.SetDayHighLowInfo(m_CurIndex);

            // 각 부분별로 신호를 추출한다.
            // 지수 파동을 먼저 만들어 준다.
            m_ETWaveSignalManager.MakeWave(m_CurIndex);
            m_WaveSignal = m_ETWaveSignalManager.GetWaveSignal(m_CurIndex);
            m_ForeSignal = m_ETWaveSignalManager.GetForecastingSignal(m_CurIndex);
            m_BuySellSignal = m_ETHogaSignalManager.GetBuySellSignal(m_CurIndex);
            // 선형 회귀를 사용하여 매수호가와 매도호가의 중간값 목록을 구한다.
            //m_ETHogaSignalManager.MakeBuyMidValueList(m_CurIndex, GlobalVar.RegressionType, GlobalVar.HogaReferenceRange);
            //m_ETHogaSignalManager.MakeSellMidValueList(m_CurIndex, GlobalVar.RegressionType, GlobalVar.HogaReferenceRange);
            m_ETHogaSignalManager.MakeWave(m_CurIndex);
            m_ETHogaSignalManager.GetBuySellSquare(m_CurIndex, ref m_BuySquare, ref m_SellSquare);
            m_ETHogaSignalManager.GetTotalBuySellSquare(m_CurIndex, ref m_TotalBuySquare, ref m_TotalSellSquare, ref m_TotalHogaSquare);
            m_ETHogaSignalManager.GetBuySellTimeOccupation(m_CurIndex, ref m_BuyTimeOcc, ref m_SellTimeOcc);
            m_ETSubjectSignalManager.MakeWave(m_CurIndex);
            m_ETSubjectSignalManager.GetCallPutTimeOccupation(m_CurIndex, ref m_CallTimeOcc, ref m_PutTimeOcc);
            m_ETSubjectSignalManager.GetTotalCallPutSquare(m_CurIndex, ref m_CallSquareOcc, ref m_PutSquareOcc, ref m_CallPutTotalSquareOcc);

            m_BidsAsksSignal = m_ETHogaSignalManager.GetBidsAsksSignal(m_CurIndex);
            m_OrganPersonKospiSignal = m_ETSubjectSignalManager.GetOrganPersonKospiSignal(m_KospiOrganInfo, m_CurIndex);
            m_ForeignPersonKospiSignal = m_ETSubjectSignalManager.GetForeignPersonKospiSignal(m_KospiForeignInfo, m_CurIndex);
            m_OptionCallPutSignal = m_ETSubjectSignalManager.GetPersonPutCallSignal(m_CurIndex);
            m_ProgramSignal = m_ETSubjectSignalManager.GetProgramSignal(m_ProgramInfo, m_CurIndex);
            m_FutureSignal = m_ETSubjectSignalManager.GetForeighFutureSignal(m_FutureForeignInfo, m_CurIndex);
            m_HighLowSignal = m_ETHighLowSignalManager.GetHighLowSignal(m_CurIndex);
            m_WorldSignal = GetWorldCurSignal();
            
            m_TotalSignal = 0.0;
            int factCount = GetSigSourceCount();
            double fact = Convert.ToDouble(factCount);
            

            if (fact != 0)
                m_TotalSignal = m_TotalSignal / fact;
            else
                m_TotalSignal = 0.0;

            GlobalVar.PriceAngle = m_FutOptPriceInfo.Angle;
            if (m_TotalSignal != 0.0)
                GlobalVar.ProgressVal = (int)m_TotalSignal;
            else
                GlobalVar.ProgressVal = 0;

            // 전체 예측 선형회귀를 구한다. 전체적인 대세를 보기 위해서이다.
            m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_PureForeInfo, "종가", GlobalVar.RegressionType, 0, m_CurIndex, false);
            // 신호 발생 가능 구간의 고가와 저가를 구한다. 
            // 이 고가와 저가를 기반으로 지수파동의 전환을 확인한다.
            m_SignalHighLowInfo = m_ETWaveSignalManager.FindSignalHeightInfo(m_CurIndex);
            // 현재 값을 얻어 온다.
            m_CurVal = GetCurVal(m_CurIndex);
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal)
            {
                m_CurWave = m_ETWaveSignalManager.EasyTraderWaveManager.GetCurWave();
                m_PreWave = m_ETWaveSignalManager.EasyTraderWaveManager.GetPreWave();
            }
            else
            {
                m_CurWave = m_ETWaveSignalManager.EasyTraderWaveManager.GetCurWave(m_CurIndex);
                m_PreWave = m_ETWaveSignalManager.EasyTraderWaveManager.GetPreWave(m_CurIndex);
            }

            // 하락 파동의 총 높이를 구한다.
            m_WaveSumDown = m_ETWaveSignalManager.EasyTraderWaveManager.SumWaveHeight(GlobalVar.PriceDown);
            // 상승 파동의 총 높이를 구한다.
            m_WaveSumUp = m_ETWaveSignalManager.EasyTraderWaveManager.SumWaveHeight(GlobalVar.PriceUp);

            // 최초 단파를 가져온다.
            EasyTrader.Wave.PriceWave curShortWave = m_ETWaveSignalManager.EasyTraderWaveManager.GetCurFirstWave(m_CurIndex);
            if (curShortWave != null)
            {
                double dayHigh = m_ETHighLowSignalManager.DayCloseMax;
                double dayLow = m_ETHighLowSignalManager.DayCloseMin;
                double startVal = m_CurVal;
                startVal = curShortWave.EndY;
                // 기준값을 중심으로 하방으로 교차한 개수를 구한다.
                if (m_CurVal == dayHigh)
                    m_CrossCount = m_ETWaveSignalManager.EasyTraderWaveManager.GetWaveCrossDownCount(m_CurIndex, dayHigh, 0.05, startVal, 360);
                // 기준값을 중심으로 상방으로 교차한 개수를 구한다.
                if (m_CurVal == dayLow)
                    m_CrossCount = m_ETWaveSignalManager.EasyTraderWaveManager.GetWaveCrossUpCount(m_CurIndex, dayLow, 0.05, startVal, 360);
            }

            int bsPower = GlobalVar.PowerNone;
            int hogaLiquidLimit = GlobalVar.MaxHogaLiquidLimit;
            // 호가의 최적의 정점 개수를 구한다. 
            CalcLiquidLimitPower(m_CurIndex, ref bsPower, ref hogaLiquidLimit);

            // 호가 신호를 위한 준비를 한다.
            PrepareHogaVal(m_CurIndex);
            // 현재 파동의 최소, 최대값을 구한다.
            m_ETWaveSignalManager.FindWaveHighLow(m_CurWave);
            //EasyTrader.Signal.PriceSignal signal = FindSignal(dayIndex);
            // 호가 상태 로그를 기록한다.
            WriteHogaLog(m_CurIndex);
            // 시스템 상태 로그를 기록한다.
            WriteStateLog(m_CurIndex);
            // 신호를 추가한다.
            //signal = CheckAddSignal(dayIndex, m_PriceSignalList, signal);
            //signal = FindMainSignalByGuideSignal(dayIndex);
            // 신호를 추가한다.
            //signal = CheckAddSignal(dayIndex, m_MainSignalList, signal);
            // 최종 신호로 주문을 보낸다.
            //SendOrder(dayIndex, signal, true);
            //CheckLiquidAll(dayIndex);
        }

        public EasyTrader.Signal.PriceSignal FindFirstSignalBySysType(int a_SysType, int a_FirstSigType, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            int hogaFromStart = m_ETHogaSignalManager.GetHogaFromStart(m_CurIndex);
          
            int startHour = 0;
            int startMin = 0;
            if (a_SysType == GlobalVar.SysTypeJisuWaveHogaSummit)
            {
                startHour = JisuWaveHogaSummitSysVar.SysStartHour;
                startMin = JisuWaveHogaSummitSysVar.SysStartMin;
            }
            else if (a_SysType == GlobalVar.SysTypeJisuWave)
            {
                startHour = JisuWaveSysVar.SysStartHour;
                startMin = JisuWaveSysVar.SysStartMin;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaWave)
            {
                startHour = HogaWaveSysVar.SysStartHour;
                startMin = HogaWaveSysVar.SysStartMin;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSquareOcc)
            {
                startHour = HogaSquareOccSysVar.SysStartHour;
                startMin = HogaSquareOccSysVar.SysStartMin;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSummit)
            {
                startHour = HogaSummitSysVar.SysStartHour;
                startMin = HogaSummitSysVar.SysStartMin;
            }
            else if (a_SysType == GlobalVar.SysTypeCallPutSquareOcc)
            {
                startHour = CallPutSquareOccSysVar.SysStartHour;
                startMin = CallPutSquareOccSysVar.SysStartMin;
            }
            else if (a_SysType == GlobalVar.SysTypePureHogaSummit)
            {
                startHour = PureHogaSummitSysVar.SysStartHour;
                startMin = PureHogaSummitSysVar.SysStartMin;
            }
            else if (a_SysType == GlobalVar.SysTypeLooseHogaSummit)
            {
                startHour = LooseHogaSummitSysVar.SysStartHour;
                startMin = LooseHogaSummitSysVar.SysStartMin;
            }
            else if (a_SysType == GlobalVar.SysTypeCallPutInvDiv)
            {
                startHour = CallPutInvDivSysVar.SysStartHour;
                startMin = CallPutInvDivSysVar.SysStartMin;
            }
            else if (a_SysType == GlobalVar.SysTypeTipAttack)
            {
                startHour = TipAttackSysVar.SysStartHour;
                startMin = TipAttackSysVar.SysStartMin;
            }
            else if (a_SysType == GlobalVar.SysTypeOptPrice)
            {
                startHour = OptPriceSysVar.SysStartHour;
                startMin = OptPriceSysVar.SysStartMin;
            }


            if (a_FirstSigType == GlobalVar.FirstSigByHogaAngle)
            {
                return FindFirstSignalByHogaAngle(m_CurIndex, startHour, startMin, a_LogFileName, ref a_CurSignal);
            }
            else if (a_FirstSigType == GlobalVar.FirstSigByJisu)
            {
                return FindFirstSignalByHeight(m_CurIndex, startHour, startMin, a_LogFileName, ref a_CurSignal);
            }
            else if (a_FirstSigType == GlobalVar.FirstSigByHogaDelta)
            {
                return FindFirstSignalByHogaDelta(m_CurIndex, startHour, startMin, a_LogFileName, ref a_CurSignal);
            }
            else if (a_FirstSigType == GlobalVar.FirstSigByWaveCount)
            {
                return FindFirstSignalByWaveCount(m_CurIndex, startHour, startMin, a_LogFileName, ref a_CurSignal);
            }
            else if (a_FirstSigType == GlobalVar.FirstSigByHogaAngleNHeight)
            {
                return FindFirstSignalByHogaAngleNHeight(m_CurIndex, startHour, startMin, a_LogFileName, ref a_CurSignal);
            }
            else if (a_FirstSigType == GlobalVar.FirstSigByHogaDeltaNHeight)
            {
                return FindFirstSignalByHogaDeltaNHeight(m_CurIndex, startHour, startMin, a_LogFileName, ref a_CurSignal);
            }
            else if (a_FirstSigType == GlobalVar.FirstSigByWaveCounNHeight)
            {
                return FindFirstSignalByWaveCountNHeight(m_CurIndex, startHour, startMin, a_LogFileName, ref a_CurSignal);
            }
            else
                return FindFirstSignalByHogaAngleNHeight(m_CurIndex, startHour, startMin, a_LogFileName, ref a_CurSignal);
        }

        public EasyTrader.Signal.PriceSignal FindSignalBySysType(PriceSignalList a_SignalList, int a_SysType, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            if (a_SysType == GlobalVar.SysTypeJisuWaveHogaSummit)
            {
                return FindSignalJisuWaveHogaSummit(a_SignalList, a_LogFileName, ref a_CurSignal);
            }
            else if (a_SysType == GlobalVar.SysTypeHogaWave)
            {
                return FindSignalHogaWave(a_SignalList, a_LogFileName, ref a_CurSignal);
            }
            else if (a_SysType == GlobalVar.SysTypeJisuWave)
            {
                return FindSignalJisuWave(a_SignalList, a_LogFileName, ref a_CurSignal);
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSquareOcc)
            {
                return FindSignalHogaSquareOcc(a_SignalList, a_LogFileName, ref a_CurSignal);
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSummit)
            {
                return FindSignalHogaSummit(a_SignalList, a_LogFileName, ref a_CurSignal);
            }
            return null;
        }

        public EasyTrader.Signal.PriceSignal FindSignalHogaSquareOcc(PriceSignalList a_SignalList, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            if (m_CurWave == null || HogaSquareOccSysVar.SysEnable == false)
                return null;

            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal(a_SignalList);
            double totalSquare = m_TotalHogaSquare;
            double buyRatio = 0.0;
            double sellRatio = 0.0;
            if (totalSquare != 0)
            {
                buyRatio = (Convert.ToDouble(totalSquare - m_TotalSellSquare) / totalSquare);
                sellRatio = (Convert.ToDouble(totalSquare - m_TotalBuySquare) / totalSquare);
            }

            if (m_CurVal == 0.0)
                return null;

            if (lastSignal == null)
            {
                if (buyRatio > sellRatio)
                {
                    double delta = buyRatio - sellRatio;
                    if (m_CurWave.Slope == GlobalVar.PriceUp && delta >= HogaSquareOccSysVar.MinSquareOccDelta)
                    {
                        SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                        WriteSignalLog("첫신호매수", a_LogFileName, a_CurSignal);
                        return a_CurSignal;
                    }
                }
                else if (sellRatio > buyRatio)
                {
                    double delta = sellRatio - buyRatio;
                    if (m_CurWave.Slope == GlobalVar.PriceDown && delta >= HogaSquareOccSysVar.MinSquareOccDelta)
                    {
                        SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                        WriteSignalLog("첫신호매도", a_LogFileName, a_CurSignal);
                        return a_CurSignal;
                    }
                }
            }

            if (lastSignal == null)
                return null;

            // 현재 신호에 따라서 신호 시작점을 깨지않는한 현재 신호를 유지한다.
            if (lastSignal.Type == GlobalVar.SignalBuy)
            {
                if (m_CurVal > lastSignal.SignalCloseMin)
                    return null;
            }
            else if (lastSignal.Type == GlobalVar.SignalSell)
            {
                if (m_CurVal < lastSignal.SignalCloseMax)
                    return null;
            }

            ForecastingInfo curForeInfo = m_ETWaveSignalManager.ForeInfo;


            if (lastSignal.Type == GlobalVar.SignalBuy)
            {
                double maxCloseHigh = m_ETHighLowSignalManager.DayCloseMax - HogaSquareOccSysVar.MaxLoss;
                if (m_CurWave.Slope == GlobalVar.PriceDown && curForeInfo.EndY < maxCloseHigh)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaSquareOccSysVar.LiquidByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("매수완전청산", a_LogFileName, a_CurSignal);
                    HogaSquareOccSysVar.SysEnable = false;
                    return a_CurSignal;
                }
            }
            else if (lastSignal.Type == GlobalVar.SignalSell)
            {
                double maxCloseLow = m_ETHighLowSignalManager.DayCloseMin + HogaSquareOccSysVar.MaxLoss;
                   if (m_CurWave.Slope == GlobalVar.PriceUp && curForeInfo.EndY > maxCloseLow)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaSquareOccSysVar.LiquidByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("매도완전청산", a_LogFileName, a_CurSignal);
                    HogaSquareOccSysVar.SysEnable = false;
                    return a_CurSignal;
                }
            }

            // 먼저 이전 신호에 대하여 대응을 해준다.
            if (lastSignal.Type == GlobalVar.SignalBuy)
            {
                double midVal = lastSignal.SignalCloseMin - HogaSquareOccSysVar.LossMargin;
                double sigVal = lastSignal.Y - GlobalVar.MaxLossMargin;
                double limitVal = Math.Max(midVal, sigVal);
                if (m_CurWave.Slope == GlobalVar.PriceDown && curForeInfo.EndY < limitVal)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaSquareOccSysVar.LiquidByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("매수청산", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }
            else if (lastSignal.Type == GlobalVar.SignalSell)
            {
                double midVal = lastSignal.SignalCloseMax + HogaSquareOccSysVar.LossMargin;
                double sigVal = lastSignal.Y + GlobalVar.MaxLossMargin;
                double limitVal = Math.Min(midVal, sigVal);
                if (m_CurWave.Slope == GlobalVar.PriceUp && curForeInfo.EndY > limitVal)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaSquareOccSysVar.LiquidByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("매도청산", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }

            

            if (buyRatio > sellRatio)
            {
                double delta = buyRatio - sellRatio;
                if (lastSignal.Type != GlobalVar.SignalBuy && m_CurWave.Slope == GlobalVar.PriceUp && delta > HogaSquareOccSysVar.MinSquareOccDelta)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaSquareOccSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                    WriteSignalLog("전환매수", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }
            else if (sellRatio > buyRatio)
            {
                double delta = sellRatio - buyRatio;
                if (lastSignal.Type != GlobalVar.SignalSell && m_CurWave.Slope == GlobalVar.PriceDown && delta > HogaSquareOccSysVar.MinSquareOccDelta)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaSquareOccSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                    WriteSignalLog("전환매도", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }

            return null;
        }


        public EasyTrader.Signal.PriceSignal FindSignalCallPutSquareOcc(PriceSignalList a_SignalList, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            if (m_CurWave == null)
                return null;

            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal(a_SignalList);
            double totalSquare = m_CallPutTotalSquareOcc;
            double callRatio = 0.0;
            double putRatio = 0.0;
            if (totalSquare != 0)
            {
                callRatio = (Convert.ToDouble(totalSquare - m_CallSquareOcc) / totalSquare);
                putRatio = (Convert.ToDouble(totalSquare - m_PutSquareOcc) / totalSquare);
            }

            if (m_CurVal == 0.0)
                return null;

            if (lastSignal == null)
            {
                if (callRatio > putRatio)
                {
                    double delta = callRatio - putRatio;
                    if (m_CurWave.Slope == GlobalVar.PriceUp && delta >= CallPutSquareOccSysVar.MinSquareOccDelta)
                    {
                        if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && CallPutSquareOccSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                        {
                            return null;
                        }
                        SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                        WriteSignalLog("첫신호매수", a_LogFileName, a_CurSignal);
                        return a_CurSignal;
                    }
                }
                else if (putRatio > callRatio)
                {
                    double delta = putRatio - callRatio;
                    if (m_CurWave.Slope == GlobalVar.PriceDown && delta >= CallPutSquareOccSysVar.MinSquareOccDelta)
                    {
                        if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && CallPutSquareOccSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                        {
                            return null;
                        }
                        SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                        WriteSignalLog("첫신호매도", a_LogFileName, a_CurSignal);
                        return a_CurSignal;
                    }
                }
            }
            if (lastSignal == null)
                return null;

            // 현재 신호에 따라서 신호 시작점을 깨지않는한 현재 신호를 유지한다.
            if (lastSignal.Type == GlobalVar.SignalBuy)
            {
                if (m_CurVal > lastSignal.SignalCloseMin)
                    return null;
            }
            else if (lastSignal.Type == GlobalVar.SignalSell)
            {
                if (m_CurVal < lastSignal.SignalCloseMax)
                    return null;
            }

            ForecastingInfo curForeInfo = m_ETWaveSignalManager.ForeInfo;

            // 먼저 이전 신호에 대하여 대응을 해준다.
            if (lastSignal.Type == GlobalVar.SignalBuy)
            {
                double midVal = lastSignal.SignalCloseMin - CallPutSquareOccSysVar.LossMargin;
                double sigVal = lastSignal.Y - GlobalVar.MaxLossMargin;
                double limitVal = Math.Max(midVal, sigVal);
                if (m_CurWave.Slope == GlobalVar.PriceDown && curForeInfo.EndY < limitVal)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && CallPutSquareOccSysVar.LiquidByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("매수청산", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }
            else if (lastSignal.Type == GlobalVar.SignalSell)
            {
                double midVal = lastSignal.SignalCloseMax + CallPutSquareOccSysVar.LossMargin;
                double sigVal = lastSignal.Y + GlobalVar.MaxLossMargin;
                double limitVal = Math.Min(midVal, sigVal);
                if (m_CurWave.Slope == GlobalVar.PriceUp && curForeInfo.EndY > limitVal)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && CallPutSquareOccSysVar.LiquidByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("매도청산", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }



            if (callRatio > putRatio)
            {
                double delta = callRatio - putRatio;
                if (lastSignal.Type != GlobalVar.SignalBuy && m_CurWave.Slope == GlobalVar.PriceUp && delta > CallPutSquareOccSysVar.MinSquareOccDelta)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && CallPutSquareOccSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                    WriteSignalLog("전환매수", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }
            else if (putRatio > callRatio)
            {
                double delta = putRatio - callRatio;
                if (lastSignal.Type != GlobalVar.SignalSell && m_CurWave.Slope == GlobalVar.PriceDown && delta > CallPutSquareOccSysVar.MinSquareOccDelta)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && CallPutSquareOccSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                    WriteSignalLog("전환매도", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }

            return null;
        }

        // 호가 여러가지 값들을 
        private int PrepareHogaVal(int a_CurIndex)
        {
            PriceSignal lastSignal = GetLastSignal(m_HogaTransSignalList);
            if (lastSignal == null)
                return -1;

            // 신호가 발생한 호가 파동을 얻어 온다.
            // 발생한 신호가 매수파동이면 매수 파동에서 매도파동이면 매도 파동에서 구해 온다.
            EasyTrader.Wave.PriceWave lastSigWave = m_ETHogaSignalManager.FindSignalWave(a_CurIndex, lastSignal.WaveType);
            if (lastSigWave == null)
                return -1;

            m_ETHogaSignalManager.GetForecastingInfo(m_BuyReg, "매수총호가건수", GlobalVar.RegressionType, a_CurIndex, GlobalVar.HogaReferenceRange, false);
            m_ETHogaSignalManager.GetForecastingInfo(m_SellReg, "매도총호가건수", GlobalVar.RegressionType, a_CurIndex, GlobalVar.HogaReferenceRange, false);
            m_CurBuyWave = m_ETHogaSignalManager.FindBuyWave(a_CurIndex);
            m_CurSellWave = m_ETHogaSignalManager.FindSellWave(a_CurIndex);
            m_BuyDayHigh = m_ETHogaSignalManager.GetBuyDayHigh(a_CurIndex);
            m_SellDayHigh = m_ETHogaSignalManager.GetSellDayHigh(a_CurIndex);
            // 호가 파동의 최고점과 최소점을 구한다.
            if (lastSignal.WaveType == GlobalVar.WaveTypeBuy)
            {
                m_BuyHighLowInfo = m_ETHogaSignalManager.FindSellSignalHighLow(a_CurIndex, lastSigWave);
            }
            else if (lastSignal.WaveType == GlobalVar.WaveTypeSell)
            {
                m_SellHighLowInfo = m_ETHogaSignalManager.FindBuySignalHighLow(a_CurIndex, lastSigWave);
            }

            return 1;
        }

        private void CheckLiquidAll()
        {
            int a_CurIndex = GlobalVar.DayIndex();
            int curTime = GlobalVar.DayIndexToTime(a_CurIndex);
            // 장 종료 시간에 모두 청산
            if (curTime == GlobalVar.TimeToInt(GlobalVar.SignalEndHour, GlobalVar.SignalEndMin))
            {
                EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal();
                if (lastSignal != null && lastSignal.Type != GlobalVar.SignalExitBuy && lastSignal.Type != GlobalVar.SignalExitSell)
                {
                    int signalVal = GlobalVar.SignalNone;
                    if (lastSignal.Type == GlobalVar.SignalBuy)
                        signalVal = GlobalVar.SignalExitBuy;
                    else if (lastSignal.Type == GlobalVar.SignalSell)
                        signalVal = GlobalVar.SignalExitSell;
                    SetStateInfo(a_CurIndex, signalVal, GlobalVar.SignalStateLiquid);
                    EasyTrader.Signal.PriceSignal signal = m_CurSignal.Clone();
                    AddSignal(signal);
                    return;
                }
            }
        }

        public void CheckLiquidAll(int a_CurIndex)
        {
            int curTime = GlobalVar.DayIndexToTime(a_CurIndex);
            // 장 종료 시간에 모두 청산
            if (curTime == GlobalVar.TimeToInt(GlobalVar.SignalEndHour, GlobalVar.SignalEndMin))
            {
                EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal();
                if (lastSignal != null && lastSignal.Type != GlobalVar.SignalExitBuy && lastSignal.Type != GlobalVar.SignalExitSell)
                {
                    int signalVal = GlobalVar.SignalNone;
                    if (lastSignal.Type == GlobalVar.SignalBuy)
                        signalVal = GlobalVar.SignalExitBuy;
                    else if (lastSignal.Type == GlobalVar.SignalSell)
                        signalVal = GlobalVar.SignalExitSell;
                    SetStateInfo(a_CurIndex, signalVal, GlobalVar.SignalStateLiquid);
                    EasyTrader.Signal.PriceSignal signal = m_CurSignal.Clone();
                    AddSignal(signal);
                    return;
                }
            }
        }

        public void CheckLiquidAll(int a_CurIndex, int a_EndHour, int a_EndMin, EasyTrader.Signal.PriceSignal a_LastSignal)
        {
            int curTime = GlobalVar.DayIndexToTime(a_CurIndex);
            // 장 종료 시간에 모두 청산
            if (curTime == GlobalVar.TimeToInt(a_EndHour, a_EndMin))
            {
                if (a_LastSignal != null && a_LastSignal.Type != GlobalVar.SignalExitBuy && a_LastSignal.Type != GlobalVar.SignalExitSell)
                {
                    int signalVal = GlobalVar.SignalNone;
                    if (a_LastSignal.Type == GlobalVar.SignalBuy)
                        signalVal = GlobalVar.SignalExitBuy;
                    else if (a_LastSignal.Type == GlobalVar.SignalSell)
                        signalVal = GlobalVar.SignalExitSell;
                    SetStateInfo(a_CurIndex, signalVal, GlobalVar.SignalStateLiquid);
                    EasyTrader.Signal.PriceSignal signal = m_CurSignal.Clone();
                    AddSignal(signal);
                    return;
                }
            }
        }

        public void CheckLiquidAllBySysType(int a_CurIndex, int a_SysType, EasyTrader.Signal.PriceSignal a_Signal, ref EasyTrader.Signal.PriceSignal a_CurSignal, PriceSignalList a_SignalList, string a_HashCode, string a_LogFileName)
        {
            int sysEndHour = GlobalVar.SignalEndHour;
            int sysEndMin = GlobalVar.SignalEndMin;
            bool EnableProfitLiquid = false;
            double ProfitLiquidValue = 0.0;
            bool EnableLossLiquid = false;
            double LossLiquidValue = 0.0;
            int OrderEndHour = GlobalVar.OrderEndHour;
            int OrderEndMin = GlobalVar.OrderEndMin;
            bool AutoOrder = GlobalVar.AutoOrder;

            if (a_SysType == GlobalVar.SysTypeJisuWaveHogaSummit)
            {
                AutoOrder = JisuWaveHogaSummitSysVar.AutoOrder;
                sysEndHour = JisuWaveHogaSummitSysVar.SysEndHour;
                sysEndMin = JisuWaveHogaSummitSysVar.SysEndMin;
                EnableProfitLiquid = JisuWaveHogaSummitSysVar.EnablePerProfitLiquid;
                ProfitLiquidValue = JisuWaveHogaSummitSysVar.PerProfitLiquidValue;
                EnableLossLiquid = JisuWaveHogaSummitSysVar.EnablePerLossLiquid;
                LossLiquidValue = JisuWaveHogaSummitSysVar.PerLossLiquidValue;
                OrderEndHour = JisuWaveHogaSummitSysVar.OrderEndHour;
                OrderEndMin = JisuWaveHogaSummitSysVar.OrderEndMin;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaWave)
            {
                AutoOrder = HogaWaveSysVar.AutoOrder;
                sysEndHour = HogaWaveSysVar.SysEndHour;
                sysEndMin = HogaWaveSysVar.SysEndMin;
                EnableProfitLiquid = HogaWaveSysVar.EnablePerProfitLiquid;
                ProfitLiquidValue = HogaWaveSysVar.PerProfitLiquidValue;
                EnableLossLiquid = HogaWaveSysVar.EnablePerLossLiquid;
                LossLiquidValue = HogaWaveSysVar.PerLossLiquidValue;
                OrderEndHour = HogaWaveSysVar.OrderEndHour;
                OrderEndMin = HogaWaveSysVar.OrderEndMin;
            }
            else if (a_SysType == GlobalVar.SysTypeJisuWave)
            {
                AutoOrder = JisuWaveSysVar.AutoOrder;
                sysEndHour = JisuWaveSysVar.SysEndHour;
                sysEndMin = JisuWaveSysVar.SysEndMin;
                EnableProfitLiquid = JisuWaveSysVar.EnablePerProfitLiquid;
                ProfitLiquidValue = JisuWaveSysVar.PerProfitLiquidValue;
                EnableLossLiquid = JisuWaveSysVar.EnablePerLossLiquid;
                LossLiquidValue = JisuWaveSysVar.PerLossLiquidValue;
                OrderEndHour = JisuWaveSysVar.OrderEndHour;
                OrderEndMin = JisuWaveSysVar.OrderEndMin;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSquareOcc)
            {
                AutoOrder = HogaSquareOccSysVar.AutoOrder;
                sysEndHour = HogaSquareOccSysVar.SysEndHour;
                sysEndMin = HogaSquareOccSysVar.SysEndMin;
                EnableProfitLiquid = HogaSquareOccSysVar.EnablePerProfitLiquid;
                ProfitLiquidValue = HogaSquareOccSysVar.PerProfitLiquidValue;
                EnableLossLiquid = HogaSquareOccSysVar.EnablePerLossLiquid;
                LossLiquidValue = HogaSquareOccSysVar.PerLossLiquidValue;
                OrderEndHour = HogaSquareOccSysVar.OrderEndHour;
                OrderEndMin = HogaSquareOccSysVar.OrderEndMin;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSummit)
            {
                sysEndHour = HogaSummitSysVar.SysEndHour;
                sysEndMin = HogaSummitSysVar.SysEndMin;
                EnableProfitLiquid = HogaSummitSysVar.EnablePerProfitLiquid;
                ProfitLiquidValue = HogaSummitSysVar.PerProfitLiquidValue;
                EnableLossLiquid = HogaSummitSysVar.EnablePerLossLiquid;
                LossLiquidValue = HogaSummitSysVar.PerLossLiquidValue;
                OrderEndHour = HogaSummitSysVar.OrderEndHour;
                OrderEndMin = HogaSummitSysVar.OrderEndMin;
            }

            int curTime = GlobalVar.DayIndexToTime(a_CurIndex);

            if (AutoOrder == true)
            {
                // 주문 종료 시간에 자동 청산
                if (curTime == GlobalVar.TimeToInt(OrderEndHour, OrderEndMin))
                {
                    m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(AutoOrder, a_HashCode);
                    SetAutoOrderBySysType(a_SysType, false);
                    return;
                }

            }

            // 전체 이익에 의한 청산
            double totalProfit = CalcTotalProfit(a_SignalList, m_ETHighLowSignalManager.CurVal);
            if (EnableProfitLiquid == true)
            {
                if (ProfitLiquidValue > 0 && totalProfit > ProfitLiquidValue)
                {
                    WriteSignalLog(a_CurIndex, a_Signal.Type, "최대이익 제한으로 모두 청산주문 나감", a_LogFileName);
                    // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                    if (AutoOrder == true)
                        m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(AutoOrder, a_HashCode);
                    SetAutoOrderBySysType(a_SysType, false);
                    return;
                }
            }

            if (EnableLossLiquid == true)
            {
                if (LossLiquidValue > 0 && totalProfit <= -LossLiquidValue)
                {
                    WriteSignalLog(a_CurIndex, a_Signal.Type, "최대손실 제한으로 모두 청산주문 나감", a_LogFileName);
                    // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                    if (AutoOrder == true)
                        m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(AutoOrder, a_HashCode);
                    SetAutoOrderBySysType(a_SysType, false);
                    return;
                }
            }
            // 장 종료 시간에 모두 청산
            if (curTime == GlobalVar.TimeToInt(sysEndHour, sysEndMin))
            {
                if (a_Signal != null && a_Signal.Type != GlobalVar.SignalExitBuy && a_Signal.Type != GlobalVar.SignalExitSell)
                {
                    int signalVal = GlobalVar.SignalNone;
                    if (a_Signal.Type == GlobalVar.SignalBuy)
                        signalVal = GlobalVar.SignalExitBuy;
                    else if (a_Signal.Type == GlobalVar.SignalSell)
                        signalVal = GlobalVar.SignalExitSell;
                    SetStateInfo(a_CurIndex, signalVal, GlobalVar.SignalStateLiquid, ref a_CurSignal);
                    EasyTrader.Signal.PriceSignal signal = a_CurSignal.Clone();
                    AddSignal(a_SignalList, signal);
                    return;
                }
            }
        }

        private int SendAutoLiquid(int a_CurIndex)
        {
            int signal = GlobalVar.SignalNone;
            if (GlobalVar.LiquidApply == false)
                return signal;
            if (m_SignalWave == null)
                return signal;
            EasyTrader.Wave.PriceWave curWave = m_ETWaveSignalManager.EasyTraderWaveManager.GetCurWave(a_CurIndex);
            if (curWave == null)
                return signal;
            double curVal = GetCurVal(a_CurIndex);
            if (curVal == 0.0)
                return signal;

            // 자동 스탑에 의한 청산 신호를 보낸다.
            // 신호 시작점을 기준으로 청산됨
            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal();
            if (GlobalVar.LiquidMethod == GlobalVar.LiquidByPercent)
            {
                // 기준파 반대 방향일 때만 적용
                // 기준파 끝점을 기준으로 청산됨
                // 기준파가 평균높이보다 클때만 적용됨
                if (lastSignal != null && m_SignalWave.Height() >= GlobalVar.SignalWaveHeight && m_SignalWave.Slope != curWave.Slope)
                {
                    if (m_ReverseRatio >= GlobalVar.LiquidPercent)
                    {
                        if (lastSignal.Type == GlobalVar.SignalSell && curWave.Slope == GlobalVar.PriceUp)
                        {
                            signal = GlobalVar.SignalExitSell;
                        }
                        
                        if (lastSignal.Type == GlobalVar.SignalBuy && curWave.Slope == GlobalVar.PriceDown)
                        {
                            signal = GlobalVar.SignalExitBuy;
                        }
                    }
                }
            }
            else if (GlobalVar.LiquidMethod == GlobalVar.LiquidByPrice)
            {
                if (lastSignal != null)
                {
                    double deltaProfit = curVal - lastSignal.Y;
                    if ( (GlobalVar.AutoProfitStopPrice != 0 && deltaProfit >= GlobalVar.AutoProfitStopPrice) || 
                        (GlobalVar.AutoLossStopPrice != 0 && deltaProfit <= -GlobalVar.AutoLossStopPrice))
                    {
                        if (lastSignal.Type == GlobalVar.SignalBuy)
                        {
                            signal = GlobalVar.SignalExitBuy;
                        }
                        else if (lastSignal.Type == GlobalVar.OrderSell)
                        {
                            signal = GlobalVar.SignalExitSell;
                        }
                    }
                }
            }
            else
            {
                if (lastSignal != null)
                {
                    if (m_ReverseRatio >= GlobalVar.LiquidPercent)
                    {
                        if (lastSignal.Type == GlobalVar.SignalSell && curWave.Slope == GlobalVar.PriceUp)
                        {
                            signal = GlobalVar.SignalExitSell;
                        }

                        if (lastSignal.Type == GlobalVar.SignalBuy && curWave.Slope == GlobalVar.PriceDown)
                        {
                            signal = GlobalVar.SignalExitBuy;
                        }
                    }

                    double deltaProfit = curVal - lastSignal.Y;
                    if ((GlobalVar.AutoProfitStopPrice != 0 && deltaProfit >= GlobalVar.AutoProfitStopPrice) ||
                        (GlobalVar.AutoLossStopPrice != 0 && deltaProfit <= -GlobalVar.AutoLossStopPrice))
                    {
                        if (lastSignal.Type == GlobalVar.SignalBuy)
                        {
                            signal = GlobalVar.SignalExitBuy;
                        }
                        else if (lastSignal.Type == GlobalVar.OrderSell)
                        {
                            signal = GlobalVar.SignalExitSell;
                        }
                    }
                }
            }

            return signal;
        }

        private bool IsKospiForeignOrganSameDirection(ref int a_Direction)
        {
            if (m_KospiForeignInfo == null || m_KospiOrganInfo == null)
                return false;
            double deltaForeign = m_KospiForeignInfo.EndY - m_KospiForeignInfo.StartY;
            double deltaOrgan = m_KospiOrganInfo.EndY - m_KospiOrganInfo.StartY;
            if (deltaOrgan > 0 && deltaForeign > 0)
            {
                a_Direction = GlobalVar.PriceUp;
                return true;
            }
            if (deltaOrgan < 0 && deltaForeign < 0)
            {
                a_Direction = GlobalVar.PriceDown;
                return true;
            }

            return false;
        }

        private bool IsKospiForeignOrganProgramSameDirection(ref int a_Direction)
        {
            if (m_KospiForeignInfo == null || m_KospiOrganInfo == null || m_ProgramInfo == null)
                return false;
            double deltaForeign = m_KospiForeignInfo.EndY - m_KospiForeignInfo.StartY;
            double deltaOrgan = m_KospiOrganInfo.EndY - m_KospiOrganInfo.StartY;
            double deltaProgram = m_ProgramInfo.EndY - m_ProgramInfo.StartY;
            if (deltaOrgan > 0 && deltaForeign > 0 && deltaProgram > 0)
            {
                a_Direction = GlobalVar.PriceUp;
                return true;
            }
            if (deltaOrgan < 0 && deltaForeign < 0 && deltaProgram < 0)
            {
                a_Direction = GlobalVar.PriceDown;
                return true;
            }

            return false;
        }

        private bool IsKospiForeignOrganProgramFutureForeignSameDirection(ref int a_Direction)
        {
            if (m_KospiForeignInfo == null || 
                m_KospiOrganInfo == null || 
                m_ProgramInfo == null ||
                m_FutureForeignInfo == null)
                return false;
            double deltaForeign = m_KospiForeignInfo.EndY - m_KospiForeignInfo.StartY;
            double deltaOrgan = m_KospiOrganInfo.EndY - m_KospiOrganInfo.StartY;
            double deltaProgram = m_ProgramInfo.EndY - m_ProgramInfo.StartY;
            double deltaFutureForeign = m_FutureForeignInfo.EndY - m_FutureForeignInfo.StartY;
            if (deltaOrgan > 0 && deltaForeign > 0 && deltaProgram > 0 && deltaFutureForeign > 0)
            {
                a_Direction = GlobalVar.PriceUp;
                return true;
            }
            if (deltaOrgan < 0 && deltaForeign < 0 && deltaProgram < 0 && deltaFutureForeign < 0)
            {
                a_Direction = GlobalVar.PriceDown;
                return true;
            }

            return false;
        }

        public EasyTrader.Signal.PriceSignal FindSignalByComplex()
        {
             //return FindSignalByValue(a_CurIndex);
             //return FindSignalByBuySell(a_CurIndex);
            return FindSignalJisuWaveHogaSummit(m_PriceSignalList, "SystemLog.txt", ref m_CurSignal);
        }
        // 이 함수는 파동과 고저 정보를 이용하여 신호를 검출한다.
        // 파동진폭 0.7까지는 파동방향으로만 신호를 내되, 파동의 높이가 0.3미만에서는 신호를 내지 않는다.
        // 이때 최고점에서 0.4, 최저점에서 0.4 지점에 왔을 때 파동이 상향이면 매수, 하향이면 매도를 각각 낸다.
        // 파동 진폭이 0.7이상에서는 기준파 진폭의 25-75에서 파동방향으로 신호를 낸다.
        // 진폭의 최저점이나 최고점을 돌파할 때는 돌파하는 파동의 방향으로 신호를 낸다.
        public int FindSignalByPercent(int a_CurIndex, ref int a_SignalState)
        {
            int signalVal = GlobalVar.SignalNone;

            if (m_ETHighLowSignalManager == null || m_ETWaveSignalManager == null)
                return signalVal;
            double curVal = GetCurVal(a_CurIndex);
            if (curVal == 0.0)
                return signalVal;
            ForecastingInfo curForeInfo = m_ETWaveSignalManager.ForeInfo;
            // 신호를 발생시킬 고저 폭을 구한다.
            //HighLowInfo m_HighLowInfo = m_ETWaveSignalManager.FindSignalHeightInfo(a_CurIndex);
            // 현재 파동을 가져온다.
            EasyTrader.Wave.PriceWave curWave = m_ETWaveSignalManager.EasyTraderWaveManager.GetCurWave(a_CurIndex);
            // 이전에 발생한 신호를 가져온다.
            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal();
            if (curForeInfo == null || m_SignalHighLowInfo == null || curWave == null || lastSignal == null)
                return signalVal;
            // 신호가 발생한 파동을 가져온다.
            EasyTrader.Wave.PriceWave lastSigWave = m_ETWaveSignalManager.FindArrangeWave(lastSignal.X);
            if (lastSigWave == null)
                return signalVal;
            // 신호가 발생한 파동과 현재 파동이 같은 파동인지 조사한다.
            bool sameWaveOrder = EasyTrader.Wave.WaveManager.IsSameWave(lastSigWave, curWave);
            // 파동의 최소, 최대값을 구한다.
            m_ETWaveSignalManager.FindWaveHighLow(curWave);
            m_ETWaveSignalManager.FindWaveHighLow(lastSigWave);
            // 신호가 발생된 이후의 예측값을 구한다.
            if (sameWaveOrder == true)
                m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_CurWaveForeInfo, "종가", GlobalVar.RegressionType, Math.Max(0, curWave.StartX - GlobalVar.ForecastCompLen), curWave.EndX - 1, false);
            else
                m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_CurWaveForeInfo, "종가", GlobalVar.RegressionType, Math.Max(0,lastSigWave.EndX - GlobalVar.ForecastCompLen), a_CurIndex, false);
            
            // 예측 파동 최소 높이에서는 반응하지 않음
            if (m_CurWaveForeInfo.Height() <= GlobalVar.MinForeInfoHeight)
            {
                WriteSignalLog(a_CurIndex, signalVal, "현재 예측파동 높이가 너무 낮아 신호거부");
                return signalVal;
            }
            
            // 최소 높이에서는 반응하지 않음
            if (m_SignalHighLowInfo.HighLowHeight() < GlobalVar.MinSignalHeight)
            {
                WriteSignalLog(a_CurIndex, signalVal, "현재 진폭이 신호발생 최소 높이보다 낮아 신호거부");
                return signalVal;
            }
            
            // 신호 필터링이 되어 있는지 점검한다.
            if (GlobalVar.AfterFirstSignalFilter == true)
            {
                // 신호 필터링 값들
                // 주체별 포지션 필터링
                bool subjectSel = false;
                // 개인 옵션 필터링
                if (GlobalVar.OptionExtremeCase == true && IsOptionPersonExtremeCase() != true)
                    return signalVal;

                // 코스피 개인,기관,외국인 방향에 의한 필터링
                int direction = GlobalVar.PriceFlat;
                if (GlobalVar.SubjectSelection == 1)
                {
                    subjectSel = IsKospiForeignOrganSameDirection(ref direction);
                    if (subjectSel != true)
                    {
                        WriteSignalLog(a_CurIndex, signalVal, "코스피외국인기관 방향이 같지 않아 신호거부");
                        return signalVal;
                    }
                }
                else if (GlobalVar.SubjectSelection == 2)
                {
                    subjectSel = IsKospiForeignOrganProgramSameDirection(ref direction);
                    if (subjectSel != true)
                    {
                        WriteSignalLog(a_CurIndex, signalVal, "코스피외국인기관프로그램 방향이 같지 않아 신호거부");
                        return signalVal;
                    }
                }
                else if (GlobalVar.SubjectSelection == 3)
                {
                    subjectSel = IsKospiForeignOrganProgramFutureForeignSameDirection(ref direction);
                    if (subjectSel != true)
                    {
                        WriteSignalLog(a_CurIndex, signalVal, "코스피외국인기관프로그램외국인선물 방향이 같지 않아 신호거부");
                        return signalVal;
                    }
                }


                // 신호 필터링은 정식 신호 파동이 생긴이후에 두번째 신호부터 이루어 진다.
                if (m_ETWaveSignalManager.GetArrangedWaveCount() > 1 && m_SignalHighLowInfo.HighLowHeight() >= GlobalVar.MaxHighLowHeight && lastSignal != null)
                {
                    double totalPercent = Math.Abs(m_TotalSignal);
                    /*
                    if (totalPercent < GlobalVar.MinSignalPercent)
                    {
                        WriteSignalLog(a_CurIndex, signalVal, "전체 퍼센트가 너무낮아 신호거부");
                        return signalVal;
                    }*/
                    // 마지막 신호가 전체 신호와 방향이 같고 정해진 퍼센트를 넘을 때는 모든 신호를 무시한다.
                    if (lastSignal.Type == GlobalVar.SignalBuy && m_TotalSignal > 0 && totalPercent >= GlobalVar.MaxSignalPercent)
                    {
                        WriteSignalLog(a_CurIndex, signalVal, "전체 퍼센트가 너무 높아 신호거부");
                        return signalVal;
                    }
                    if (lastSignal.Type == GlobalVar.SignalSell && m_TotalSignal < 0 && totalPercent >= GlobalVar.MaxSignalPercent)
                    {
                        WriteSignalLog(a_CurIndex, signalVal, "전체 퍼센트가 너무 높아 신호거부");
                        return signalVal;
                    }

                    // 최소 호가 건수 필터링
                    if (GlobalVar.MinDeltaBuySellEnable == true && DeltaHogaBuySell < GlobalVar.MinDeltaBuySell)
                    {
                        WriteSignalLog(a_CurIndex, signalVal, "호가 건수 차이가 너무 적어 신호거부");
                        return signalVal;
                    }
                    // 최소 호가 잔량 필터링
                    if (GlobalVar.MinDeltaBidsAsksEnable == true && DeltaHogaBidsAsks < GlobalVar.MinDeltaBidsAsks)
                    {
                        WriteSignalLog(a_CurIndex, signalVal, "호가 잔량 차이가 너무 적어 신호거부");
                        return signalVal;
                    }
                    
                    // 호가 건수에서 매수가 높은 경우
                    if (m_HogaBuyInfo.PureEndY > m_HogaSellInfo.PureEndY && lastSignal.Type == GlobalVar.SignalBuy)
                    {
                        // 최대 호가 건수 필터링
                        if (GlobalVar.MaxDeltaBuySellEnable == true && DeltaHogaBuySell > GlobalVar.MaxDeltaBuySell)
                        {
                            WriteSignalLog(a_CurIndex, signalVal, "매수우위 호가 건수 차이가 너무 커 신호거부");
                            return signalVal;
                        }
                    }
                    if (m_HogaSellInfo.PureEndY > m_HogaBuyInfo.PureEndY && lastSignal.Type == GlobalVar.SignalSell) // 호가 건수에서 매도가 높은 경우
                    {
                        // 최대 호가 건수 필터링
                        if (GlobalVar.MaxDeltaBuySellEnable == true && DeltaHogaBuySell > GlobalVar.MaxDeltaBuySell)
                        {
                            WriteSignalLog(a_CurIndex, signalVal, "매도우위 호가 건수 차이가 너무 커 신호거부");
                            return signalVal;
                        }
                    }

                    if (m_HogaBidsInfo.PureEndY > m_HogaAsksInfo.PureEndY && lastSignal.Type == GlobalVar.SignalBuy)
                    {
                        // 최대 호가 잔량 필터링
                        if (GlobalVar.MaxDeltaBidsAsksEnable == true && DeltaHogaBidsAsks > GlobalVar.MaxDeltaBidsAsks)
                        {
                            WriteSignalLog(a_CurIndex, signalVal, "매수우위 호가 잔량 차이가 너무 커 신호거부");
                            return signalVal;
                        }
                    }
                    if (m_HogaAsksInfo.PureEndY > m_HogaBidsInfo.PureEndY && lastSignal.Type == GlobalVar.SignalSell)
                    {
                        // 최대 호가 잔량 필터링
                        if (GlobalVar.MaxDeltaBidsAsksEnable == true && DeltaHogaBidsAsks > GlobalVar.MaxDeltaBidsAsks)
                        {
                            WriteSignalLog(a_CurIndex, signalVal, "매도우위 호가 잔량 차이가 너무 커 신호거부");
                            return signalVal;
                        }
                    }
                }
            }
            int bidaskLen = 0;
            int bidaskCrossCount = m_ETHogaSignalManager.GetBidsAsksCrossCount(a_CurIndex, ref bidaskLen);
            int buysellLen = 0;
            int buysellCrossCount = m_ETHogaSignalManager.GetBuySellCrossCount(a_CurIndex, ref buysellLen);
            // 신호가 발생한 파동과 현재 파동이 동일한 범위에 있는 경우
            // 예측 파동과 이미 들어간 신호가 다르면 반대 주문을 내어 준다.
            if (sameWaveOrder == true)
            {
                double firstHighY = m_SignalHighLowInfo.HighY - m_SignalHighLowInfo.HighLowHeight() * GlobalVar.MinHighLowPercent;
                double firstLowY = m_SignalHighLowInfo.LowY + m_SignalHighLowInfo.HighLowHeight() * GlobalVar.MinHighLowPercent;
                if (m_SignalHighLowInfo.MinMaxHeight() >= GlobalVar.MaxCloseHeight)
                {
                    // 파동의 근원과 변동성도 고려해서 신호를 내줘야 함.
                    double secondHighY = m_SignalHighLowInfo.CloseMax - m_SignalHighLowInfo.MinMaxHeight() * GlobalVar.MinClosePercent;
                    double secondLowY = m_SignalHighLowInfo.CloseMin + m_SignalHighLowInfo.MinMaxHeight() * GlobalVar.MinClosePercent;
                    double highZoneVal = Math.Min(firstHighY, secondHighY);
                    double lowZoneVal = Math.Max(firstLowY, secondLowY);
                    if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceUp)
                    {
                        if (curWave.LowY <= firstLowY && curWave.LowY < m_ETHighLowSignalManager.LowLimit && curForeInfo.EndY > lowZoneVal)
                        {
                            signalVal = GlobalVar.SignalBuy;
                            WriteSignalLog(a_CurIndex, signalVal, "큰높이 수정 상방전환 매수신호");
                            a_SignalState = GlobalVar.SignalStateTrans;
                        }
                        if (curForeInfo.EndY > (m_SignalHighLowInfo.CloseMax + GlobalVar.CloseCompVal))
                        {
                            signalVal = GlobalVar.SignalBuy;
                            WriteSignalLog(a_CurIndex, signalVal, "큰높이 수정 상방돌파 매수신호");
                            a_SignalState = GlobalVar.SignalStateOver;
                        }
                    }
                    else if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceDown)
                    {
                        if (curWave.HighY >= firstHighY && curWave.HighY > m_ETHighLowSignalManager.HighLimit && curForeInfo.EndY < highZoneVal)
                        {
                            signalVal = GlobalVar.SignalSell;
                            WriteSignalLog(a_CurIndex, signalVal, "큰높이 수정 하방전환 매도신호");
                            a_SignalState = GlobalVar.SignalStateTrans;
                        }

                        if (curForeInfo.EndY < (m_SignalHighLowInfo.CloseMin - GlobalVar.CloseCompVal))
                        {
                            signalVal = GlobalVar.SignalSell;
                            WriteSignalLog(a_CurIndex, signalVal, "큰높이 수정 하방돌파 매도신호");
                            a_SignalState = GlobalVar.SignalStateOver;
                        }
                    }
                }
                else
                {
                    double lowZoneVal = m_SignalHighLowInfo.LowY + GlobalVar.MinHighLowHeight;
                    double highZoneVal = m_SignalHighLowInfo.HighY - GlobalVar.MinHighLowHeight;
                    if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceUp)
                    {
                        if (curWave.LowY <= firstLowY && curWave.LowY < m_ETHighLowSignalManager.LowLimit && curForeInfo.EndY > lowZoneVal)
                        {
                            signalVal = GlobalVar.SignalBuy;
                            WriteSignalLog(a_CurIndex, signalVal, "작은 높이 수정 상방전환 매수신호");
                            a_SignalState = GlobalVar.SignalStateTrans;
                        }
                        if (curForeInfo.EndY > (m_SignalHighLowInfo.CloseMax + GlobalVar.CloseCompVal))
                        {
                            signalVal = GlobalVar.SignalBuy;
                            WriteSignalLog(a_CurIndex, signalVal, "작은 높이 수정 상방돌파 매수신호");
                            a_SignalState = GlobalVar.SignalStateOver;
                        }
                    }
                    else if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceDown)
                    {
                        if (curWave.HighY >= firstHighY && curWave.HighY > m_ETHighLowSignalManager.HighLimit && curForeInfo.EndY < highZoneVal)
                        {
                            signalVal = GlobalVar.SignalSell;
                            WriteSignalLog(a_CurIndex, signalVal, "작은 높이 수정 하방전환 매도신호");
                            a_SignalState = GlobalVar.SignalStateTrans;
                        }
                        if (curForeInfo.EndY < (m_SignalHighLowInfo.CloseMin - GlobalVar.CloseCompVal))
                        {
                            signalVal = GlobalVar.SignalSell;
                            WriteSignalLog(a_CurIndex, signalVal, "작은 높이 수정 하방돌파 매도신호");
                            a_SignalState = GlobalVar.SignalStateOver;
                        }
                    }
                }
            }
            else
            {
                double firstHighY = m_SignalHighLowInfo.HighY - m_SignalHighLowInfo.HighLowHeight() * GlobalVar.MinHighLowPercent;
                double firstLowY = m_SignalHighLowInfo.LowY + m_SignalHighLowInfo.HighLowHeight() * GlobalVar.MinHighLowPercent;
                if (m_SignalHighLowInfo.MinMaxHeight() >= GlobalVar.MaxCloseHeight)
                {
                    // 파동의 근원과 변동성도 고려해서 신호를 내줘야 함.
                    double secondHighY = m_SignalHighLowInfo.CloseMax - m_SignalHighLowInfo.MinMaxHeight() * GlobalVar.MinClosePercent;
                    double secondLowY = m_SignalHighLowInfo.CloseMin + m_SignalHighLowInfo.MinMaxHeight() * GlobalVar.MinClosePercent;
                    double highZoneVal = Math.Min(firstHighY, secondHighY);
                    double lowZoneVal = Math.Max(firstLowY, secondLowY);
                    if (m_CurWaveForeInfo.Len() <= GlobalVar.MaxForeInfoLen)
                    {
                        if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceUp)
                        {
                            if (curWave.LowY <= firstLowY && curWave.LowY < m_ETHighLowSignalManager.LowLimit && curForeInfo.EndY > lowZoneVal)
                            {
                                signalVal = GlobalVar.SignalBuy;
                                WriteSignalLog(a_CurIndex, signalVal, "큰높이 상방전환 매수신호");
                                a_SignalState = GlobalVar.SignalStateTrans;
                            }
                            if (curForeInfo.EndY > (m_SignalHighLowInfo.CloseMax + GlobalVar.CloseCompVal))
                            {
                                signalVal = GlobalVar.SignalBuy;
                                WriteSignalLog(a_CurIndex, signalVal, "큰높이 상방돌파 매수신호");
                                a_SignalState = GlobalVar.SignalStateOver;
                            }
                        }
                        else if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceDown)
                        {
                            if (curWave.HighY >= firstHighY && curWave.HighY > m_ETHighLowSignalManager.HighLimit && curForeInfo.EndY < highZoneVal)
                            {
                                signalVal = GlobalVar.SignalSell;
                                WriteSignalLog(a_CurIndex, signalVal, "큰높이 하방전환 매도신호");
                                a_SignalState = GlobalVar.SignalStateTrans;
                            }

                            if (curForeInfo.EndY < (m_SignalHighLowInfo.CloseMin - GlobalVar.CloseCompVal))
                            {
                                signalVal = GlobalVar.SignalSell;
                                WriteSignalLog(a_CurIndex, signalVal, "큰높이 하방돌파 매도신호");
                                a_SignalState = GlobalVar.SignalStateOver;
                            }
                        }
                    }
                    else
                    {
                        if (curWave.Slope == GlobalVar.PriceUp)
                        {
                            if (curWave.LowY <= firstLowY && curWave.LowY < m_ETHighLowSignalManager.LowLimit && curForeInfo.EndY > lowZoneVal)
                            {
                                signalVal = GlobalVar.SignalBuy;
                                WriteSignalLog(a_CurIndex, signalVal, "큰높이 상방전환 매수신호");
                                a_SignalState = GlobalVar.SignalStateTrans;
                            }
                            if (curForeInfo.EndY > (m_SignalHighLowInfo.CloseMax + GlobalVar.CloseCompVal))
                            {
                                signalVal = GlobalVar.SignalBuy;
                                WriteSignalLog(a_CurIndex, signalVal, "큰높이 상방돌파 매수신호");
                                a_SignalState = GlobalVar.SignalStateOver;
                            }
                        }
                        else if (curWave.Slope == GlobalVar.PriceDown)
                        {
                            if (curWave.HighY >= firstHighY && curWave.HighY > m_ETHighLowSignalManager.HighLimit && curForeInfo.EndY < highZoneVal)
                            {
                                signalVal = GlobalVar.SignalSell;
                                WriteSignalLog(a_CurIndex, signalVal, "큰높이 하방전환 매도신호");
                                a_SignalState = GlobalVar.SignalStateTrans;
                            }

                            if (curForeInfo.EndY < (m_SignalHighLowInfo.CloseMin - GlobalVar.CloseCompVal))
                            {
                                signalVal = GlobalVar.SignalSell;
                                WriteSignalLog(a_CurIndex, signalVal, "큰높이 하방돌파 매도신호");
                                a_SignalState = GlobalVar.SignalStateOver;
                            }
                        }
                    }
                }
                else
                {
                    double lowZoneVal = m_SignalHighLowInfo.LowY + GlobalVar.MinHighLowHeight;
                    double highZoneVal = m_SignalHighLowInfo.HighY - GlobalVar.MinHighLowHeight;
                    if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceUp)
                    {
                        if (curWave.LowY <= firstLowY && curWave.LowY < m_ETHighLowSignalManager.LowLimit && curForeInfo.EndY > lowZoneVal)
                        {
                            signalVal = GlobalVar.SignalBuy;
                            WriteSignalLog(a_CurIndex, signalVal, "작은 높이 상방전환 매수신호");
                            a_SignalState = GlobalVar.SignalStateTrans;
                        }
                        if (curForeInfo.EndY > (m_SignalHighLowInfo.CloseMax + GlobalVar.CloseCompVal))
                        {
                            signalVal = GlobalVar.SignalBuy;
                            WriteSignalLog(a_CurIndex, signalVal, "작은 높이 상방돌파 매수신호");
                            a_SignalState = GlobalVar.SignalStateOver;
                        }
                    }
                    else if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceDown)
                    {
                        if (curWave.HighY >= firstHighY && curWave.HighY > m_ETHighLowSignalManager.HighLimit && curForeInfo.EndY < highZoneVal)
                        {
                            signalVal = GlobalVar.SignalSell;
                            WriteSignalLog(a_CurIndex, signalVal, "작은 높이 하방전환 매도신호");
                            a_SignalState = GlobalVar.SignalStateTrans;
                        }
                        if (curForeInfo.EndY < (m_SignalHighLowInfo.CloseMin - GlobalVar.CloseCompVal))
                        {
                            signalVal = GlobalVar.SignalSell;
                            WriteSignalLog(a_CurIndex, signalVal, "작은 높이 하방돌파 매도신호");
                            a_SignalState = GlobalVar.SignalStateOver;
                        }
                    }
                }
            }
            return signalVal;
        }

        private EasyTrader.Signal.ForecastingInfo m_BuyVal = new EasyTrader.Signal.ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo BuyVal
        {
            get { return m_BuyVal; }
            set { m_BuyVal = value; }
        }
        private EasyTrader.Signal.ForecastingInfo m_SellVal = new EasyTrader.Signal.ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo SellVal
        {
            get { return m_SellVal; }
            set { m_SellVal = value; }
        }

        public EasyTrader.Signal.PriceSignal FindMainSignalByGuideSignal(int a_CurIndex)
        {
            PriceSignal lastSignal = GetLastSignal(m_PriceSignalList);
            PriceSignal lastMainSignal = GetLastSignal(m_MainSignalList);
            if (lastSignal == null)
                return null;
            int bsPower = GlobalVar.PowerNone;
            int hogaLiquidLimit = GlobalVar.MaxHogaLiquidLimit;
            CalcLiquidLimitPower(a_CurIndex, ref bsPower, ref hogaLiquidLimit);
            if (lastSignal.Type == GlobalVar.SignalBuy)
            {
                if (m_CurWave.Slope == GlobalVar.PriceUp)
                {
                    if (lastMainSignal == null)
                    {
                        SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans);
                        WriteSignalLog("호가정점이전지수상방전환 매수신호", m_CurSignal);
                        return m_CurSignal;
                    }
                    else
                    {
                        if (lastMainSignal.Type != GlobalVar.SignalBuy)
                        {
                            SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans);
                            WriteSignalLog("호가정점이전지수상방전환 매수신호", m_CurSignal);
                            return m_CurSignal;
                        }
                    }
                }
            }
            else if (lastSignal.Type == GlobalVar.SignalSell)
            {
                if (m_CurWave.Slope == GlobalVar.PriceDown)
                {
                    if (lastMainSignal == null)
                    {
                        SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans);
                        WriteSignalLog("호가정점이전지수상방전환 매수신호", m_CurSignal);
                        return m_CurSignal;
                    }
                    else
                    {
                        if (lastMainSignal.Type != GlobalVar.SignalSell)
                        {
                            SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans);
                            WriteSignalLog("호가정점이전지수상방전환 매수신호", m_CurSignal);
                            return m_CurSignal;
                        }
                    }
                }
            }

            if (lastMainSignal != null)
            {
                if (lastMainSignal.Type == GlobalVar.SignalBuy)
                {
                    if (m_CurWave.Slope == GlobalVar.PriceDown)
                    {
                        SetStateInfo(a_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateLiquid);
                        WriteSignalLog("호가정점이전지수상방전환 매수신호", m_CurSignal);
                        return m_CurSignal;
                    }
                }
                else if (lastMainSignal.Type == GlobalVar.SignalSell)
                {
                    if (m_CurWave.Slope == GlobalVar.PriceUp)
                    {
                        SetStateInfo(a_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateLiquid);
                        WriteSignalLog("호가정점이전지수상방전환 매수신호", m_CurSignal);
                        return m_CurSignal;
                    }
                }
            }

            return null;
        }

        public void CalcLiquidLimitPower(int a_CurIndex, ref int a_BSPower, ref int a_LiquidLimit)
        {
            double totalTime = Convert.ToDouble(m_BuyTimeOcc) + Convert.ToDouble(m_SellTimeOcc);
            double buyTimeRatio = 0.0;
            double sellTimeRatio = 0.0;

            if (totalTime != 0)
            {
                buyTimeRatio = (Convert.ToDouble(m_BuyTimeOcc) / totalTime);
                sellTimeRatio = (Convert.ToDouble(m_SellTimeOcc) / totalTime);
            }

            int buyTimeOcc = (int)(buyTimeRatio * 100.0);
            int sellTimeOcc = (int)(sellTimeRatio * 100.0);

            double totalSquare = m_TotalHogaSquare;
            double buyRatio = 0.0;
            double sellRatio = 0.0;
            if (totalSquare != 0)
            {
                buyRatio = (Convert.ToDouble(totalSquare - m_TotalSellSquare) / totalSquare);
                sellRatio = (Convert.ToDouble(totalSquare - m_TotalBuySquare) / totalSquare);
            }


            int buySquareOcc = (int)(buyRatio * 100.0);
            int sellSquareOcc = (int)(sellRatio * 100.0);
            a_BSPower = GlobalVar.PowerNone;
            a_LiquidLimit = GlobalVar.MaxHogaLiquidLimit;
            double dayAmp = m_ETHighLowSignalManager.DayHigh - m_ETHighLowSignalManager.DayLow;
            // 시공간 점유율로 대세를 정한다. 시간점유율이 높을 때는 시공간 점유율을 같이 보고 
            // 시공간 점유율이 낮을 때는 공간 점유율로만 판단을 한다.
            if (buyTimeOcc > sellTimeOcc)
            {
                if (buyTimeOcc >= 100)
                {
                    a_BSPower = GlobalVar.PowerBuy;
                    a_LiquidLimit = 3300;
                }
                else if (buyTimeOcc < 100 && buyTimeOcc >= GlobalVar.MaxTimeOcc)
                {
                    if (buySquareOcc >= GlobalVar.MidSquareOcc)
                    {
                        a_BSPower = GlobalVar.PowerBuy;
                        a_LiquidLimit = 2900;
                    }
                }
                else
                {
                    if (sellSquareOcc <= 0)
                    {
                        a_BSPower = GlobalVar.PowerBuy;
                        a_LiquidLimit = 2900;
                    }
                    if (sellSquareOcc > 0 && sellSquareOcc <= GlobalVar.MinSquareOcc)
                    {
                        if (buySquareOcc >= GlobalVar.MaxSquareOcc)
                        {
                            a_BSPower = GlobalVar.PowerBuy;
                            if (dayAmp >= 3.0)
                                a_LiquidLimit = 3300;
                            else if (dayAmp < 3.0 && dayAmp >= 2.0)
                                a_LiquidLimit = 2900;
                            else
                                a_LiquidLimit = 2700;
                        }
                    }
                }
            }
            else
            {
                if (sellTimeOcc >= 100)
                {
                    a_BSPower = GlobalVar.PowerSell;
                    a_LiquidLimit = 3300;
                }
                else if (sellTimeOcc < 100 && sellTimeOcc >= GlobalVar.MaxTimeOcc)
                {
                    if (sellSquareOcc >= GlobalVar.MidSquareOcc)
                    {
                        a_BSPower = GlobalVar.PowerSell;
                        a_LiquidLimit = 2900;
                    }
                }
                else
                {
                    if (buySquareOcc <= 0)
                    {
                        a_BSPower = GlobalVar.PowerSell;
                        a_LiquidLimit = 2900;
                    }
                    else if (buySquareOcc > 0 && buySquareOcc <= GlobalVar.MinSquareOcc)
                    {
                        if (sellSquareOcc >= GlobalVar.MaxSquareOcc)
                        {
                            a_BSPower = GlobalVar.PowerSell;
                            if (dayAmp >= 3.0)
                                a_LiquidLimit = 3300;
                            else if (dayAmp < 3.0 && dayAmp >= 2.0)
                                a_LiquidLimit = 2900;
                            else
                                a_LiquidLimit = 2700;
                        }
                    }
                }
            }
            WriteHogaRatioLog(a_CurIndex, buyTimeOcc, sellTimeOcc, buySquareOcc, sellSquareOcc, a_BSPower, a_LiquidLimit);
        }


        private void CheckOneWay(int a_CurIndex, ref int a_BSPower)
        {
            double totalTime = Convert.ToDouble(m_BuyTimeOcc) + Convert.ToDouble(m_SellTimeOcc);
            double buyTimeRatio = 0.0;
            double sellTimeRatio = 0.0;

            if (totalTime != 0)
            {
                buyTimeRatio = (Convert.ToDouble(m_BuyTimeOcc) / totalTime);
                sellTimeRatio = (Convert.ToDouble(m_SellTimeOcc) / totalTime);
            }

            int buyTimeOcc = (int)(buyTimeRatio * 100.0);
            int sellTimeOcc = (int)(sellTimeRatio * 100.0);

            double totalSquare = m_TotalHogaSquare;
            double buyRatio = 0.0;
            double sellRatio = 0.0;
            if (totalSquare != 0)
            {
                buyRatio = (Convert.ToDouble(totalSquare - m_TotalSellSquare) / totalSquare);
                sellRatio = (Convert.ToDouble(totalSquare - m_TotalBuySquare) / totalSquare);
            }


            int buySquareOcc = (int)(buyRatio * 100.0);
            int sellSquareOcc = (int)(sellRatio * 100.0);
            a_BSPower = GlobalVar.PowerNone;

            m_BuyDayHigh = m_ETHogaSignalManager.GetBuyDayHigh(a_CurIndex);
            m_SellDayHigh = m_ETHogaSignalManager.GetSellDayHigh(a_CurIndex);
            int HogaHigh = Math.Max(m_BuyDayHigh, m_SellDayHigh);

            if (HogaHigh >= HogaSummitSysVar.OneWayMinHoga)
            {
                if (buyTimeOcc > sellTimeOcc)
                {
                    if (buyTimeOcc >= GlobalVar.OneWayMinTimeOcc && sellSquareOcc <= GlobalVar.OneWayMinSquareOcc)
                        a_BSPower = GlobalVar.PowerBuy;
                }
                else if (sellTimeOcc > buyTimeOcc)
                {
                    if (sellTimeOcc >= GlobalVar.OneWayMinTimeOcc && buySquareOcc <= GlobalVar.OneWayMinSquareOcc)
                        a_BSPower = GlobalVar.PowerSell;
                }
            }
        }

        public void CalcLiquidLimitPower(int a_CurIndex, ref int a_BSPower, ref int a_LiquidLimit, string a_LogFileName)
        {
            double totalTime = Convert.ToDouble(m_BuyTimeOcc) + Convert.ToDouble(m_SellTimeOcc);
            double buyTimeRatio = 0.0;
            double sellTimeRatio = 0.0;

            if (totalTime != 0)
            {
                buyTimeRatio = (Convert.ToDouble(m_BuyTimeOcc) / totalTime);
                sellTimeRatio = (Convert.ToDouble(m_SellTimeOcc) / totalTime);
            }

            int buyTimeOcc = (int)(buyTimeRatio * 100.0);
            int sellTimeOcc = (int)(sellTimeRatio * 100.0);

            double totalSquare = m_TotalHogaSquare;
            double buyRatio = 0.0;
            double sellRatio = 0.0;
            if (totalSquare != 0)
            {
                buyRatio = (Convert.ToDouble(totalSquare - m_TotalSellSquare) / totalSquare);
                sellRatio = (Convert.ToDouble(totalSquare - m_TotalBuySquare) / totalSquare);
            }


            int buySquareOcc = (int)(buyRatio * 100.0);
            int sellSquareOcc = (int)(sellRatio * 100.0);
            a_BSPower = GlobalVar.PowerNone;
            a_LiquidLimit = GlobalVar.MaxHogaLiquidLimit;
            double dayAmp = m_ETHighLowSignalManager.DayHigh - m_ETHighLowSignalManager.DayLow;
            // 시공간 점유율로 대세를 정한다. 시간점유율이 높을 때는 시공간 점유율을 같이 보고 
            // 시공간 점유율이 낮을 때는 공간 점유율로만 판단을 한다.
            if (buyTimeOcc > sellTimeOcc)
            {
                if (buyTimeOcc >= 100)
                {
                    a_BSPower = GlobalVar.PowerBuy;
                    a_LiquidLimit = 3300;
                }
                else if (buyTimeOcc < 100 && buyTimeOcc >= GlobalVar.MaxTimeOcc)
                {
                    if (buySquareOcc >= GlobalVar.MidSquareOcc)
                    {
                        a_BSPower = GlobalVar.PowerBuy;
                        a_LiquidLimit = 2900;
                    }
                }
                else
                {
                    if (sellSquareOcc <= 0)
                    {
                        a_BSPower = GlobalVar.PowerBuy;
                        a_LiquidLimit = 2900;
                    }
                    if (sellSquareOcc > 0 && sellSquareOcc <= GlobalVar.MinSquareOcc)
                    {
                        if (buySquareOcc >= GlobalVar.MaxSquareOcc)
                        {
                            a_BSPower = GlobalVar.PowerBuy;
                            if (dayAmp >= 3.0)
                                a_LiquidLimit = 3300;
                            else if (dayAmp < 3.0 && dayAmp >= 2.0)
                                a_LiquidLimit = 2900;
                            else
                                a_LiquidLimit = 2700;
                        }
                    }
                }
            }
            else
            {
                if (sellTimeOcc >= 100)
                {
                    a_BSPower = GlobalVar.PowerSell;
                    a_LiquidLimit = 3300;
                }
                else if (sellTimeOcc < 100 && sellTimeOcc >= GlobalVar.MaxTimeOcc)
                {
                    if (sellSquareOcc >= GlobalVar.MidSquareOcc)
                    {
                        a_BSPower = GlobalVar.PowerSell;
                        a_LiquidLimit = 2900;
                    }
                }
                else
                {
                    if (buySquareOcc <= 0)
                    {
                        a_BSPower = GlobalVar.PowerSell;
                        a_LiquidLimit = 2900;
                    }
                    else if (buySquareOcc > 0 && buySquareOcc <= GlobalVar.MinSquareOcc)
                    {
                        if (sellSquareOcc >= GlobalVar.MaxSquareOcc)
                        {
                            a_BSPower = GlobalVar.PowerSell;
                            if (dayAmp >= 3.0)
                                a_LiquidLimit = 3300;
                            else if (dayAmp < 3.0 && dayAmp >= 2.0)
                                a_LiquidLimit = 2900;
                            else
                                a_LiquidLimit = 2700;
                        }
                    }
                }
            }
            WriteHogaRatioLog(a_CurIndex, buyTimeOcc, sellTimeOcc, buySquareOcc, sellSquareOcc, a_BSPower, a_LiquidLimit, a_LogFileName);
        }

        // 매도매수 호가건수에 의해서 신호를 낸다.
        public EasyTrader.Signal.PriceSignal FindSignalHogaWave(PriceSignalList a_SignalList, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            PriceSignal lastSignal = GetLastSignal(a_SignalList);
            if (lastSignal == null)
                return null;

            // 신호가 발생한 파동의 시작점에서 현재까지 선형회귀값을 구한다.
            m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_LastSignalRegression, "종가", GlobalVar.RegressionType, Math.Max(0, lastSignal.X - GlobalVar.ForecastCompLen), m_CurIndex, false);
            // 현재 파동에 대한 선형회귀 값을 구한다.
            m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_CurWaveRegression, "종가", GlobalVar.RegressionType, Math.Max(0, m_CurWave.StartX - GlobalVar.ForecastCompLen), m_CurIndex, false);

            int bsPower = GlobalVar.PowerNone;
            int hogaLiquidLimit = GlobalVar.MaxHogaLiquidLimit;
            CalcLiquidLimitPower(m_CurIndex, ref bsPower, ref hogaLiquidLimit, a_LogFileName);

            if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
            {
                m_CurBuyWave = m_ETHogaSignalManager.FindBuyWave(m_CurIndex);
                m_CurSellWave = m_ETHogaSignalManager.FindSellWave(m_CurIndex);
            }
            else
            {
                m_CurBuyWave = m_ETHogaSignalManager.FindLastBuyWave(m_CurIndex);
                m_CurSellWave = m_ETHogaSignalManager.FindLastSellWave(m_CurIndex);
            }
            int lowBuy = 0;
            int lowSell = 0;

            m_BuyDayHigh = m_ETHogaSignalManager.GetBuyDayHigh(m_CurIndex, ref lowSell);
            m_SellDayHigh = m_ETHogaSignalManager.GetSellDayHigh(m_CurIndex, ref lowBuy);
            //m_BuyDayHigh = m_ETHogaSignalManager.GetBuyDayHigh(a_CurIndex);
            //m_SellDayHigh = m_ETHogaSignalManager.GetSellDayHigh(a_CurIndex);
            int buyFirst = 0, sellFirst = 0;
            m_ETHogaSignalManager.GetFirstBuySell(m_CurIndex, ref buyFirst, ref sellFirst);
            int deltaBuyFirst = buyFirst + GlobalVar.MinHogaLiquidLimit;
            int deltaSellFirst = sellFirst + GlobalVar.MinHogaLiquidLimit;
            // 파동의 최소, 최대값을 구한다.
            m_ETHogaSignalManager.FindBuyWaveHighLow(m_CurBuyWave);
            m_ETHogaSignalManager.FindSellWaveHighLow(m_CurSellWave);
            if (m_CurBuyWave == null || m_CurSellWave == null)
                return null;

            double curBuyVal = m_ETHogaSignalManager.GetBuyAveVal();
            double curSellVal = m_ETHogaSignalManager.GetSellAveVal();

            double sellAveMin = 0.0, sellAveMax = 0.0;
            double buyAveMin = 0.0, buyAveMax = 0.0;

            m_ETHogaSignalManager.FindSellWaveAveHighLow(m_CurSellWave, ref sellAveMax, ref sellAveMin);
            m_ETHogaSignalManager.FindBuyWaveAveHighLow(m_CurBuyWave, ref buyAveMax, ref buyAveMin);
            double minMaxDelta = 0.0;
            if (buyAveMax > sellAveMax)
            {
                minMaxDelta = buyAveMax - sellAveMin;
            }
            else if (sellAveMax > buyAveMax)
            {
                minMaxDelta = sellAveMax - buyAveMin;
            }
            if (minMaxDelta <= JisuWaveHogaSummitSysVar.MinTurnHogaMaxMinDelta)
                return null;

            if (m_CurBuyWave.HighY > m_CurSellWave.HighY)
            {
                // 정점에서 내려올 때
                // 현재 하락 중인 매수 파동
                if (m_CurBuyWave.Slope == GlobalVar.PriceDown)
                {
                    // 호가 3000을 넘었을 때
                    if (m_BuyDayHigh > hogaLiquidLimit)
                    {
                        if (m_CurSellWave.GetSlope() != GlobalVar.PriceDown &&
                            m_BuyDayHigh > lowSell &&
                            m_BuyDayHigh > lastSignal.BuyDayHigh &&
                            deltaBuyFirst < m_BuyDayHigh)
                        {
                            int deltaY = m_BuyDayHigh - Convert.ToInt32(curBuyVal);
                            if (deltaY > GlobalVar.MinHogaLimit)
                            {
                                if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaWaveSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                                {
                                    return null;
                                }
                                // 매수가 정점에 도달했으므로 매도 신호를 내준다.
                                SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                WriteSignalLog("호가매수수렴정점전환매도", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                    }
                }
                else if (m_CurBuyWave.Slope == GlobalVar.PriceUp) // 현재 상승중인 매수파동 - 매도파동은 하락하고 있을 때
                {
                    if (bsPower != GlobalVar.PowerSell)
                    {
                        // 정점이전 대응
                        if (m_BuyDayHigh < hogaLiquidLimit)
                        {
                            if (m_CurSellWave.GetSlope() != GlobalVar.PriceUp &&
                                lastSignal.SellDayHigh < m_BuyDayHigh)
                            {
                                int deltaY = m_SellDayHigh - Convert.ToInt32(curSellVal);
                                if (deltaY > GlobalVar.MinHogaLimit)
                                {
                                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaWaveSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                                    {
                                        return null;
                                    }
                                    // 매도가 정점에 도달했으므로 매수 신호를 내준다.
                                    SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                    WriteSignalLog("정점이전호가매도열세발산정점전환매수", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                        }
                        else // 정점이후 대응
                        {
                            if (m_CurSellWave.GetSlope() != GlobalVar.PriceUp)
                            {
                                int deltaY = Convert.ToInt32(m_CurSellWave.HighY) - Convert.ToInt32(curSellVal);
                                if (deltaY > GlobalVar.MinHogaLimit)
                                {
                                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaWaveSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                                    {
                                        return null;
                                    }
                                    // 매도가 정점에 도달했으므로 매수 신호를 내준다.
                                    SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                    WriteSignalLog("정점이후호가매도열세발산정점전환매수", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                // 현재 하락 중인 매도파동
                if (m_CurSellWave.Slope == GlobalVar.PriceDown)
                {
                    if (m_SellDayHigh > hogaLiquidLimit)
                    {
                        if (m_CurBuyWave.GetSlope() == GlobalVar.PriceUp &&
                            m_SellDayHigh > lowBuy &&
                            m_SellDayHigh > lastSignal.SellDayHigh &&
                            deltaSellFirst < m_SellDayHigh)
                        {
                            int deltaY = m_SellDayHigh - Convert.ToInt32(curSellVal);
                            if (deltaY > GlobalVar.MinHogaLimit)
                            {
                                if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaWaveSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                                {
                                    return null;
                                }
                                // 매도가 정점에 도달했으므로 매수 신호를 내준다.
                                SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                WriteSignalLog("호가매도수렴정점전환매수", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                    }
                }
                else if (m_CurSellWave.Slope == GlobalVar.PriceUp) // 매도 파동이 상승 중일 때
                {
                    if (bsPower != GlobalVar.PowerBuy)
                    {
                        // 정점 이전 대응
                        if (m_SellDayHigh < hogaLiquidLimit)
                        {
                            if (m_CurBuyWave.Slope == GlobalVar.PriceDown &&
                                lastSignal.BuyDayHigh < m_BuyDayHigh)
                            {
                                int deltaY = m_BuyDayHigh - Convert.ToInt32(curBuyVal);
                                if (deltaY > GlobalVar.MinHogaLimit)
                                {
                                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaWaveSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                                    {
                                        return null;
                                    }
                                    // 매수가 정점에 도달했으므로 매도 신호를 내준다.
                                    SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                    WriteSignalLog("호가매수열세발산정점전환매도", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                        }
                        else // 정점 이후 대응
                        {
                            if (m_CurBuyWave.Slope == GlobalVar.PriceDown)
                            {
                                int deltaY = Convert.ToInt32(m_CurBuyWave.HighY) - Convert.ToInt32(curBuyVal);
                                if (deltaY > GlobalVar.MinHogaLimit)
                                {
                                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaWaveSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                                    {
                                        return null;
                                    }
                                    // 매수가 정점에 도달했으므로 매도 신호를 내준다.
                                    SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                    WriteSignalLog("호가매수열세발산정점전환매도", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                        }
                    }
                }
            }

            ForecastingInfo curForeInfo = m_ETWaveSignalManager.ForeInfo;
            if (lastSignal.Type == GlobalVar.SignalBuy)
            {
                double midVal = lastSignal.SignalCloseMin - HogaWaveSysVar.LossMargin;
                double sigVal = lastSignal.Y - GlobalVar.MaxLossMargin;
                double limitVal = Math.Max(midVal, sigVal);
                if (m_CurWave.Slope == GlobalVar.PriceDown && curForeInfo.EndY < limitVal)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaWaveSysVar.LiquidByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("돌파매도", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }
            else if (lastSignal.Type == GlobalVar.SignalSell)
            {
                double midVal = lastSignal.SignalCloseMax + HogaWaveSysVar.LossMargin;
                double sigVal = lastSignal.Y + GlobalVar.MaxLossMargin;
                double limitVal = Math.Min(midVal, sigVal);
                if (m_CurWave.Slope == GlobalVar.PriceUp && curForeInfo.EndY > limitVal)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaWaveSysVar.LiquidByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("돌파매수", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }

            return null;
        }

        private void WriteTrend(int a_CurIndex, int a_Trend)
        {
            string log = "현재 트렌드 : " + a_CurIndex.ToString() + " : ";
            switch (a_Trend)
            {
                case 1:
                    log += "HighToMid";
                    break;
                case 2:
                    log += "LowToMid";
                    break;
                case 3:
                    log += "MidToHigh";
                    break;
                case 4:
                    log += "MidToLow";
                    break;
                case 5:
                    log += "HighToLow";
                    break;
                case 6:
                    log += "LowToHigh";
                    break;
                default:
                    log += "TrendNone";
                    break;
            }
            GlobalVar.WriteLog(log);
        }

        private void WriteTrend(int a_CurIndex, int a_Trend, string a_LogFileName)
        {
            string log = "현재 트렌드 : " + a_CurIndex.ToString() + " : ";
            switch (a_Trend)
            {
                case 1:
                    log += "HighToMid";
                    break;
                case 2:
                    log += "LowToMid";
                    break;
                case 3:
                    log += "MidToHigh";
                    break;
                case 4:
                    log += "MidToLow";
                    break;
                case 5:
                    log += "HighToLow";
                    break;
                case 6:
                    log += "LowToHigh";
                    break;
                default:
                    log += "TrendNone";
                    break;
            }
            GlobalVar.WriteLogWithFileName(log, a_LogFileName);
        }

        public EasyTrader.Signal.PriceSignal FindSignalJisuWaveHogaSummit(PriceSignalList a_SignalList, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal(a_SignalList);
            ForecastingInfo curForeInfo = m_ETWaveSignalManager.ForeInfo;
            if (lastSignal == null || curForeInfo == null || m_CurWave == null)
                return null;

            int highLowIndex = 0;
            double highLowVal = 0.0;
            int curTrend = GlobalVar.TrendNone;
            int result = m_ETWaveSignalManager.FindPeakIndex(m_CurIndex, m_SignalHighLowInfo, ref highLowIndex, ref highLowVal, ref curTrend);
            if (result < 0)
                return null;
            int highIndex = 0;
            double highVal = 0.0;
            result = m_ETWaveSignalManager.FindFirstHighVal(m_CurIndex, m_SignalHighLowInfo, ref highIndex, ref highVal);
            if (result < 0)
                return null;
            int lowIndex = 0;
            double lowVal = 0.0;
            result = m_ETWaveSignalManager.FindFirstLowVal(m_CurIndex, m_SignalHighLowInfo, ref lowIndex, ref lowVal);
            if (result < 0)
                return null;
            if (curTrend == GlobalVar.TrendNone)
                return null;
            
            if (highIndex > lowIndex)
            {
                result = m_ETWaveSignalManager.MakeIndexWaveInfo(m_CurIndex, m_IndexWave, highIndex, highVal);
            }
            else
            {
                result = m_ETWaveSignalManager.MakeIndexWaveInfo(m_CurIndex, m_IndexWave, lowIndex, lowVal);
            }
            
            if (result < 0)
                return null;

            WriteTrend(m_CurIndex, curTrend, a_LogFileName);

            // 신호가 발생한 파동의 시작점에서 현재까지 선형회귀값을 구한다.
            m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_LastSignalRegression, "종가", GlobalVar.RegressionType, lastSignal.X, m_CurIndex, false);
            // 현재 파동에 대한 선형회귀 값을 구한다.
            m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_CurWaveRegression, "종가", GlobalVar.RegressionType, Math.Max(highIndex, lowIndex), m_CurIndex, false);
            //if (m_LastSignalRegression.Height() <= 0.05)
            //    return null;

            double curBuyVal = m_ETHogaSignalManager.GetBuyAveVal();
            double curSellVal = m_ETHogaSignalManager.GetSellAveVal();
            int lowBuy = 0;
            int lowSell = 0;

            m_BuyDayHigh = m_ETHogaSignalManager.GetBuyDayHigh(m_CurIndex, ref lowSell);
            m_SellDayHigh = m_ETHogaSignalManager.GetSellDayHigh(m_CurIndex, ref lowBuy);
            int HogaHigh = Math.Max(m_BuyDayHigh, m_SellDayHigh);

            int deltaBuy = m_BuyDayHigh - Convert.ToInt32(curBuyVal);
            int deltaSell = m_SellDayHigh - Convert.ToInt32(curSellVal);
            int bsPower = GlobalVar.PowerNone;
            int hogaLiquidLimit = GlobalVar.MaxHogaLiquidLimit;
            CalcLiquidLimitPower(m_CurIndex, ref bsPower, ref hogaLiquidLimit, a_LogFileName);

            if (a_SignalList.Count >= 2)
            {
                if (lastSignal.Type == GlobalVar.SignalSell)
                {
                    if (lastSignal.SellDayHigh < m_SellDayHigh && deltaSell < JisuWaveHogaSummitSysVar.MinTurnHogaDelta)
                        return null;
                }
                if (lastSignal.Type == GlobalVar.SignalBuy)
                {
                    if (lastSignal.BuyDayHigh < m_BuyDayHigh && deltaBuy < JisuWaveHogaSummitSysVar.MinTurnHogaDelta)
                        return null;
                }
            }

            double sellAveMin = 0.0, sellAveMax = 0.0;
            double buyAveMin = 0.0, buyAveMax = 0.0;
            m_CurBuyWave = m_ETHogaSignalManager.FindBuyWave(m_CurIndex);
            m_CurSellWave = m_ETHogaSignalManager.FindSellWave(m_CurIndex);

            m_ETHogaSignalManager.FindSellWaveAveHighLow(m_CurSellWave, ref sellAveMax, ref sellAveMin);
            m_ETHogaSignalManager.FindBuyWaveAveHighLow(m_CurBuyWave, ref buyAveMax, ref buyAveMin);
            double minMaxDelta = 0.0;
            if (buyAveMax > sellAveMax)
            {
                minMaxDelta = buyAveMax - sellAveMin;
                if (m_BuyDayHigh > m_SellDayHigh)
                {
                    if (deltaBuy > JisuWaveHogaSummitSysVar.MinTurnHogaDelta && minMaxDelta > JisuWaveHogaSummitSysVar.MaxTurnHogaMaxMinDelta)
                    {
                        bsPower = GlobalVar.PowerNone;
                    }
                }
            }
            else if (sellAveMax > buyAveMax)
            {
                minMaxDelta = sellAveMax - buyAveMin;
                if (m_SellDayHigh > m_BuyDayHigh)
                {
                    if (deltaSell > JisuWaveHogaSummitSysVar.MinTurnHogaDelta && minMaxDelta > JisuWaveHogaSummitSysVar.MaxTurnHogaMaxMinDelta)
                    {
                        bsPower = GlobalVar.PowerNone;
                    }
                }
            }
            if (minMaxDelta <= JisuWaveHogaSummitSysVar.MinTurnHogaMaxMinDelta)
                return null;

            // 먼저 이전 신호에 대하여 대응을 해준다.
            if (lastSignal.Type == GlobalVar.SignalBuy)
            {
                double midVal = lastSignal.SignalCloseMin - JisuWaveHogaSummitSysVar.LossMargin;
                if (m_CurWave.Slope == GlobalVar.PriceDown && m_CurVal < midVal)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && JisuWaveHogaSummitSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("돌파매도", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }
            else if (lastSignal.Type == GlobalVar.SignalSell)
            {
                double midVal = lastSignal.SignalCloseMax + JisuWaveHogaSummitSysVar.LossMargin;
                if (m_CurWave.Slope == GlobalVar.PriceUp && m_CurVal > midVal)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && JisuWaveHogaSummitSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("돌파매수", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }

            // 호가로 인한 신호는 청산가능 건수보다 작을 때만 낸다.
            // 이 신호는 호가 우위의 영향을 받지 않는다.
            if (HogaHigh >= hogaLiquidLimit)
            {
                if (m_BuyDayHigh > lowSell && m_BuyDayHigh > lastSignal.BuyDayHigh && deltaBuy > JisuWaveHogaSummitSysVar.MinTurnHogaDelta)
                {
                    if (lastSignal.Type != GlobalVar.SignalSell)
                    {
                        if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && JisuWaveHogaSummitSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                        {
                            return null;
                        }
                        SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                        WriteSignalLog("호가정점전환매도", a_LogFileName, a_CurSignal);
                        return a_CurSignal;
                    }
                }

                if (m_SellDayHigh > lowBuy && m_SellDayHigh > lastSignal.SellDayHigh && deltaSell > JisuWaveHogaSummitSysVar.MinTurnHogaDelta)
                {
                    if (lastSignal.Type != GlobalVar.SignalBuy)
                    {
                        if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && JisuWaveHogaSummitSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                        {
                            return null;
                        }
                        SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                        WriteSignalLog("호가정점전환매수", a_LogFileName, a_CurSignal);
                        return a_CurSignal;
                    }
                }
            }


            double dayAmp = m_ETHighLowSignalManager.DayHigh - m_ETHighLowSignalManager.DayLow;
            if (dayAmp < 0.8)
                return null;

            double highLimit = m_SignalHighLowInfo.CloseMax - JisuWaveHogaSummitSysVar.MinTurnHeight;
            double lowLimit = m_SignalHighLowInfo.CloseMin + JisuWaveHogaSummitSysVar.MinTurnHeight;
            double lowRootLimit = m_SignalHighLowInfo.LowY + GlobalVar.WaveRootLimit;
            double highRootlLimit = m_SignalHighLowInfo.HighY - GlobalVar.WaveRootLimit;
            if (bsPower == GlobalVar.PowerNone || HogaHigh >= hogaLiquidLimit)
            {
                if (m_CurWave.Slope == GlobalVar.PriceUp)
                {
                    if (m_CurVal >= lowLimit && m_CurWave.LowY <= lowRootLimit)
                    {
                        if (m_CurWave.Height() >= GlobalVar.SignalWaveHeightLimit && lastSignal.Type != GlobalVar.SignalBuy)
                        {
                            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && JisuWaveHogaSummitSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                            {
                                return null;
                            }
                            SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                            WriteSignalLog("상방전환 매수신호", a_LogFileName, a_CurSignal);
                            return a_CurSignal;
                        }
                    }
                }
                else if (m_CurWave.Slope == GlobalVar.PriceDown)
                {
                    if (m_CurVal <= highLimit && m_CurWave.HighY >= highRootlLimit)
                    {
                        if (m_CurWave.Height() >= GlobalVar.SignalWaveHeightLimit && lastSignal.Type != GlobalVar.SignalSell)
                        {
                            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && JisuWaveHogaSummitSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                            {
                                return null;
                            }
                            SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                            WriteSignalLog("하방전환 매도신호", a_LogFileName, a_CurSignal);
                            return a_CurSignal;
                        }
                    }
                }
            }
            else
            {
                if (m_CurWave.Slope == GlobalVar.PriceUp)
                {
                    if (m_CurVal >= lowLimit && m_CurWave.LowY <= lowRootLimit)
                    {
                        if (m_CurWave.Height() >= GlobalVar.SignalWaveHeightLimit && lastSignal.Type != GlobalVar.SignalBuy)
                        {
                            if (bsPower != GlobalVar.PowerBuy)
                            {
                                if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && JisuWaveHogaSummitSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                                {
                                    return null;
                                }
                                SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                WriteSignalLog("상방전환 매수신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                    }
                }
                else if (m_CurWave.Slope == GlobalVar.PriceDown)
                {
                    if (m_CurVal <= highLimit && m_CurWave.HighY >= highRootlLimit)
                    {
                        if (m_CurWave.Height() >= GlobalVar.SignalWaveHeightLimit && lastSignal.Type != GlobalVar.SignalSell)
                        {
                            if (bsPower != GlobalVar.PowerSell)
                            {
                                if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && JisuWaveHogaSummitSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                                {
                                    return null;
                                }
                                SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                WriteSignalLog("하방전환 매도신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                    }
                }
            }
            
            return null;
        }


        public EasyTrader.Signal.PriceSignal FindSignalHogaSummit(PriceSignalList a_SignalList, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal(a_SignalList);
            ForecastingInfo curForeInfo = m_ETWaveSignalManager.ForeInfo;
            if (lastSignal == null || m_IndexWave == null || curForeInfo == null || m_CurWave == null)
                return null;

            int highLowIndex = 0;
            double highLowVal = 0.0;
            int curTrend = GlobalVar.TrendNone;
            int result = m_ETWaveSignalManager.FindPeakIndex(m_CurIndex, m_SignalHighLowInfo, ref highLowIndex, ref highLowVal, ref curTrend);
            if (result < 0)
                return null;
            int highIndex = 0;
            double highVal = 0.0;
            result = m_ETWaveSignalManager.FindFirstHighVal(m_CurIndex, m_SignalHighLowInfo, ref highIndex, ref highVal);
            if (result < 0)
                return null;
            int lowIndex = 0;
            double lowVal = 0.0;
            result = m_ETWaveSignalManager.FindFirstLowVal(m_CurIndex, m_SignalHighLowInfo, ref lowIndex, ref lowVal);
            if (result < 0)
                return null;
            if (curTrend == GlobalVar.TrendNone)
                return null;

            if (highIndex > lowIndex)
            {
                result = m_ETWaveSignalManager.MakeIndexWaveInfo(m_CurIndex, m_IndexWave, highIndex, highVal);
            }
            else
            {
                result = m_ETWaveSignalManager.MakeIndexWaveInfo(m_CurIndex, m_IndexWave, lowIndex, lowVal);
            }

            if (result < 0)
                return null;

            WriteTrend(m_CurIndex, curTrend, a_LogFileName);

            // 신호가 발생한 파동의 시작점에서 현재까지 선형회귀값을 구한다.
            m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_LastSignalRegression, "종가", GlobalVar.RegressionType, lastSignal.X, m_CurIndex, false);
            // 현재 파동에 대한 선형회귀 값을 구한다.
            m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_CurWaveRegression, "종가", GlobalVar.RegressionType, Math.Max(highIndex, lowIndex), m_CurIndex, false);
            //if (m_LastSignalRegression.Height() <= 0.05)
            //    return null;

            

            // 먼저 이전 신호에 대하여 대응을 해준다.
            if (lastSignal.Type == GlobalVar.SignalBuy)
            {
                double midVal = lastSignal.SignalCloseMin - HogaSummitSysVar.LossMargin;
                if (m_CurWave.Slope == GlobalVar.PriceDown && m_CurVal < midVal)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaSummitSysVar.LiquidByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("돌파매도", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }
            else if (lastSignal.Type == GlobalVar.SignalSell)
            {
                double midVal = lastSignal.SignalCloseMax + HogaSummitSysVar.LossMargin;
                if (m_CurWave.Slope == GlobalVar.PriceUp && m_CurVal > midVal)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaSummitSysVar.LiquidByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("돌파매수", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }

            double curBuyVal = m_ETHogaSignalManager.GetBuyAveVal();
            double curSellVal = m_ETHogaSignalManager.GetSellAveVal();
            int lowBuy = 0;
            int lowSell = 0;

            m_BuyDayHigh = m_ETHogaSignalManager.GetBuyDayHigh(m_CurIndex, ref lowSell);
            m_SellDayHigh = m_ETHogaSignalManager.GetSellDayHigh(m_CurIndex, ref lowBuy);
            int HogaHigh = Math.Max(m_BuyDayHigh, m_SellDayHigh);

            int deltaBuy = m_BuyDayHigh - Convert.ToInt32(curBuyVal);
            int deltaSell = m_SellDayHigh - Convert.ToInt32(curSellVal);
            int bsPower = GlobalVar.PowerNone;
            CheckOneWay(m_CurIndex, ref bsPower);

            if (lastSignal.Type == GlobalVar.SignalSell)
            {
                if (lastSignal.SellDayHigh < m_SellDayHigh && deltaSell < HogaSummitSysVar.MinTurnHogaDelta)
                    return null;
            }
            if (lastSignal.Type == GlobalVar.SignalBuy)
            {
                if (lastSignal.BuyDayHigh < m_BuyDayHigh && deltaBuy < HogaSummitSysVar.MinTurnHogaDelta)
                    return null;
            }

            double sellAveMin = 0.0, sellAveMax = 0.0;
            double buyAveMin = 0.0, buyAveMax = 0.0;
            m_CurBuyWave = m_ETHogaSignalManager.FindBuyWave(m_CurIndex);
            m_CurSellWave = m_ETHogaSignalManager.FindSellWave(m_CurIndex);

            m_ETHogaSignalManager.FindSellWaveAveHighLow(m_CurSellWave, ref sellAveMax, ref sellAveMin);
            m_ETHogaSignalManager.FindBuyWaveAveHighLow(m_CurBuyWave, ref buyAveMax, ref buyAveMin);
            double minMaxDelta = 0.0;
            if (buyAveMax > sellAveMax)
            {
                minMaxDelta = buyAveMax - sellAveMin;
            }
            else if (sellAveMax > buyAveMax)
            {
                minMaxDelta = sellAveMax - buyAveMin;
            }
            if (minMaxDelta <= HogaSummitSysVar.MinTurnHogaMaxMinDelta || m_CurIndex > HogaSummitSysVar.LastIndex)
                return null;

            double dayAmp = m_ETHighLowSignalManager.DayHigh - m_ETHighLowSignalManager.DayLow;
            if (dayAmp < HogaSummitSysVar.MinDayAmp)
                return null;
            // 호가로 인한 신호는 청산가능 건수보다 작을 때만 낸다.
            // 이 신호는 호가 우위의 영향을 받지 않는다.
            if (m_BuyDayHigh > lowSell && m_BuyDayHigh > lastSignal.BuyDayHigh && deltaBuy > HogaSummitSysVar.MinTurnHogaDelta)
            {
                if (m_CurBuyWave.Slope == GlobalVar.PriceDown && m_CurSellWave.Slope == GlobalVar.PriceUp)
                {
                    if (lastSignal.Type != GlobalVar.SignalSell)
                    {
                        if (bsPower != GlobalVar.PowerBuy)
                        {
                            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaSummitSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                            {
                                return null;
                            }
                            SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                            WriteSignalLog("호가정점전환매도", a_LogFileName, a_CurSignal);
                            return a_CurSignal;
                        }
                    }
                }
            }

            if (m_SellDayHigh > lowBuy && m_SellDayHigh > lastSignal.SellDayHigh && deltaSell > HogaSummitSysVar.MinTurnHogaDelta)
            {
                if (m_CurSellWave.Slope == GlobalVar.PriceDown && m_CurBuyWave.Slope == GlobalVar.PriceUp)
                {
                    if (lastSignal.Type != GlobalVar.SignalBuy)
                    {
                        if (bsPower != GlobalVar.PowerSell)
                        {
                            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && HogaSummitSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                            {
                                return null;
                            }
                            SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                            WriteSignalLog("호가정점전환매수", a_LogFileName, a_CurSignal);
                            return a_CurSignal;
                        }
                    }
                }
            }

            return null;
        }

        // 값에 의해서 신호를 전환한다.
        public EasyTrader.Signal.PriceSignal FindSignalByValue(int a_CurIndex, PriceSignalList a_SignalList, int a_AcceptSignal, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            int signalVal = GlobalVar.SignalNone;

            if (m_ETHighLowSignalManager == null || m_ETWaveSignalManager == null)
                return null;
            double curVal = GetCurVal(a_CurIndex);
            if (curVal == 0.0)
                return null;
            ForecastingInfo curForeInfo = m_ETWaveSignalManager.ForeInfo;
            // 신호를 발생시킬 고저 폭을 구한다.
            //HighLowInfo m_HighLowInfo = m_ETWaveSignalManager.FindSignalHeightInfo(a_CurIndex);
            // 현재 파동을 가져온다.
            EasyTrader.Wave.PriceWave curWave = m_ETWaveSignalManager.EasyTraderWaveManager.GetCurWave(a_CurIndex);
            // 이전에 발생한 신호를 가져온다.
            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal(a_SignalList);
            if (curForeInfo == null || m_SignalHighLowInfo == null || curWave == null || lastSignal == null)
                return null;
            // 신호가 발생한 파동을 가져온다.
            EasyTrader.Wave.PriceWave lastSigWave = m_ETWaveSignalManager.FindArrangeWave(lastSignal.X);
            if (lastSigWave == null)
                return null;
            
            // 신호가 발생한 파동과 현재 파동이 같은 파동인지 조사한다.
            bool sameWaveOrder = EasyTrader.Wave.WaveManager.IsSameWave(lastSigWave, curWave);
            // 파동의 최소, 최대값을 구한다.
            m_ETWaveSignalManager.FindWaveHighLow(curWave);
            m_ETWaveSignalManager.FindWaveHighLow(lastSigWave);
            // 신호가 발생된 이후의 예측값을 구한다.
            if (sameWaveOrder == true)
                m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_CurWaveForeInfo, "종가", GlobalVar.RegressionType, Math.Max(0, curWave.StartX - GlobalVar.ForecastCompLen), curWave.EndX - 1, false);
            else
                m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_CurWaveForeInfo, "종가", GlobalVar.RegressionType, Math.Max(0, lastSigWave.EndX - GlobalVar.ForecastCompLen), a_CurIndex, false);

            /*
            // 예측 파동 최소 높이에서는 반응하지 않음
            if (m_CurWaveForeInfo.Height() <= GlobalVar.MinForeInfoHeight)
            {
                WriteSignalLog(a_CurIndex, signalVal, "현재 예측파동 높이가 너무 낮아 신호거부");
                return signalVal;
            }*/


#region SignalFiltering By Value
            string strLog = "";

            // 최소 높이에서는 반응하지 않음
            if (m_SignalHighLowInfo.HighLowHeight() < GlobalVar.MinSignalHeight)
            {
                strLog = "현재 진폭 : " + m_SignalHighLowInfo.HighLowHeight().ToString("F2");
                strLog += ", 현재 진폭이 신호발생 최소 높이보다 낮아 신호거부";
                WriteErrorLog(a_CurIndex, strLog);
                return null;
            }

            
#endregion
            // 신호가 발생한 파동과 현재 파동이 동일한 범위에 있는 경우
            // 예측 파동과 이미 들어간 신호가 다르면 반대 주문을 내어 준다.
            if (sameWaveOrder == true)
            {
                double firstHighY = m_SignalHighLowInfo.HighY - GlobalVar.MinHighLowTransHeight;
                double firstLowY = m_SignalHighLowInfo.LowY + GlobalVar.MinHighLowTransHeight;
                if (m_SignalHighLowInfo.MinMaxHeight() >= GlobalVar.MaxCloseHeight)
                {
                    // 파동의 근원과 변동성도 고려해서 신호를 내줘야 함.
                    double secondHighY = m_SignalHighLowInfo.CloseMax - GlobalVar.MinCloseTransHeight;
                    double secondLowY = m_SignalHighLowInfo.CloseMin + GlobalVar.MinCloseTransHeight;
                    double highZoneVal = Math.Min(firstHighY, secondHighY);
                    double lowZoneVal = Math.Max(firstLowY, secondLowY);
                    if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceUp)
                    {
                        if (curWave.LowY <= firstLowY && curWave.LowY < m_ETHighLowSignalManager.LowLimit && curForeInfo.EndY > lowZoneVal)
                        {
                            if (a_AcceptSignal == GlobalVar.AcceptSellOnly)
                            {
                                if (lastSignal.Type == GlobalVar.SignalSell)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("큰높이 수정 상방전환 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                WriteSignalLog("큰높이 수정 상방전환 매수신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                        if (curForeInfo.EndY > (m_SignalHighLowInfo.CloseMax))
                        {
                            if (a_AcceptSignal == GlobalVar.AcceptSellOnly)
                            {
                                if (lastSignal.Type == GlobalVar.SignalSell)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("큰높이 수정 상방돌파 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                WriteSignalLog("큰높이 수정 상방돌파 매수신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                    }
                    else if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceDown)
                    {
                        if (curWave.HighY >= firstHighY && curWave.HighY > m_ETHighLowSignalManager.HighLimit && curForeInfo.EndY < highZoneVal)
                        {
                            if (a_AcceptSignal == GlobalVar.AcceptBuyOnly)
                            {
                                if (lastSignal.Type == GlobalVar.SignalBuy)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("큰높이 수정 하방전환 매도신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                WriteSignalLog("큰높이 수정 하방전환 매도신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }

                        if (curForeInfo.EndY < (m_SignalHighLowInfo.CloseMin))
                        {
                            if (a_AcceptSignal == GlobalVar.AcceptSellOnly)
                            {
                                if (lastSignal.Type == GlobalVar.SignalBuy)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("큰높이 수정 하방돌파 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                WriteSignalLog("큰높이 수정 하방돌파 매수신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                    }
                }
                else
                {
                    double lowZoneVal = m_SignalHighLowInfo.LowY + GlobalVar.MinHighLowHeight;
                    double highZoneVal = m_SignalHighLowInfo.HighY - GlobalVar.MinHighLowHeight;
                    if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceUp)
                    {
                        if (curWave.LowY <= firstLowY && curWave.LowY < m_ETHighLowSignalManager.LowLimit && curForeInfo.EndY > lowZoneVal)
                        {
                            if (a_AcceptSignal == GlobalVar.AcceptSellOnly)
                            {
                                if (lastSignal.Type == GlobalVar.SignalSell)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("작은 높이 수정 상방전환 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                WriteSignalLog("작은 높이 수정 상방전환 매수신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                        if (curForeInfo.EndY > (m_SignalHighLowInfo.CloseMax))
                        {
                            if (a_AcceptSignal == GlobalVar.AcceptSellOnly)
                            {
                                if (lastSignal.Type == GlobalVar.SignalSell)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("작은 높이 수정 상방돌파 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                WriteSignalLog("작은 높이 수정 상방돌파 매수신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                    }
                    else if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceDown)
                    {
                        if (curWave.HighY >= firstHighY && curWave.HighY > m_ETHighLowSignalManager.HighLimit && curForeInfo.EndY < highZoneVal)
                        {
                            if (a_AcceptSignal == GlobalVar.AcceptBuyOnly)
                            {
                                if (lastSignal.Type == GlobalVar.SignalBuy)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("작은 높이 수정 하방전환 매도신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                WriteSignalLog("작은 높이 수정 하방전환 매도신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                        if (curForeInfo.EndY < (m_SignalHighLowInfo.CloseMin))
                        {
                            if (a_AcceptSignal == GlobalVar.AcceptBuyOnly)
                            {
                                if (lastSignal.Type == GlobalVar.SignalBuy)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("작은 높이 수정 하방돌파 매도신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                WriteSignalLog("작은 높이 수정 하방돌파 매도신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                    }
                }
            }
            else
            {
                double firstHighY = m_SignalHighLowInfo.HighY - GlobalVar.MinHighLowTransHeight;
                double firstLowY = m_SignalHighLowInfo.LowY + GlobalVar.MinHighLowTransHeight;
                if (m_SignalHighLowInfo.MinMaxHeight() >= GlobalVar.MaxCloseHeight)
                {
                    // 파동의 근원과 변동성도 고려해서 신호를 내줘야 함.
                    double secondHighY = m_SignalHighLowInfo.CloseMax - GlobalVar.MinCloseTransHeight;
                    double secondLowY = m_SignalHighLowInfo.CloseMin + GlobalVar.MinCloseTransHeight;
                    double highZoneVal = Math.Min(firstHighY, secondHighY);
                    double lowZoneVal = Math.Max(firstLowY, secondLowY);
                    if (m_CurWaveForeInfo.Height() <= GlobalVar.MaxForeInfoHeight)
                    {
                        if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceUp)
                        {
                            if (curWave.LowY <= firstLowY && curWave.LowY < m_ETHighLowSignalManager.LowLimit && curForeInfo.EndY > lowZoneVal)
                            {
                                if (a_AcceptSignal == GlobalVar.AcceptSellOnly)
                                {
                                    if (lastSignal.Type == GlobalVar.SignalSell)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                        WriteSignalLog("큰높이 상방전환 매수신호", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                }
                                else
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("큰높이 상방전환 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            if (curForeInfo.EndY > (m_SignalHighLowInfo.CloseMax))
                            {
                                if (a_AcceptSignal == GlobalVar.AcceptSellOnly)
                                {
                                    if (lastSignal.Type == GlobalVar.SignalSell)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                        WriteSignalLog("큰높이 상방돌파 매수신호", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                }
                                else
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("큰높이 상방돌파 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                        }
                        else if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceDown)
                        {
                            if (curWave.HighY >= firstHighY && curWave.HighY > m_ETHighLowSignalManager.HighLimit && curForeInfo.EndY < highZoneVal)
                            {
                                if (a_AcceptSignal == GlobalVar.AcceptBuyOnly)
                                {
                                    if (lastSignal.Type == GlobalVar.SignalBuy)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                        WriteSignalLog("큰높이 하방전환 매도신호", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                }
                                else
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("큰높이 하방전환 매도신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }

                            if (curForeInfo.EndY < (m_SignalHighLowInfo.CloseMin))
                            {
                                if (a_AcceptSignal == GlobalVar.AcceptBuyOnly)
                                {
                                    if (lastSignal.Type == GlobalVar.SignalBuy)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                        WriteSignalLog("큰높이 하방돌파 매도신호", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                }
                                else
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("큰높이 하방돌파 매도신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (curWave.Slope == GlobalVar.PriceUp)
                        {
                            if (curWave.LowY <= firstLowY && curWave.LowY < m_ETHighLowSignalManager.LowLimit && curForeInfo.EndY > lowZoneVal)
                            {
                                if (a_AcceptSignal == GlobalVar.AcceptSellOnly)
                                {
                                    if (lastSignal.Type == GlobalVar.SignalSell)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                        WriteSignalLog("큰높이 상방전환 매수신호", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                }
                                else
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("큰높이 상방전환 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            if (curForeInfo.EndY > (m_SignalHighLowInfo.CloseMax))
                            {
                                if (a_AcceptSignal == GlobalVar.AcceptSellOnly)
                                {
                                    if (lastSignal.Type == GlobalVar.SignalSell)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                        WriteSignalLog("큰높이 상방돌파 매수신호", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                }
                                else
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("큰높이 상방돌파 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                        }
                        else if (curWave.Slope == GlobalVar.PriceDown)
                        {
                            if (curWave.HighY >= firstHighY && curWave.HighY > m_ETHighLowSignalManager.HighLimit && curForeInfo.EndY < highZoneVal)
                            {
                                if (a_AcceptSignal == GlobalVar.AcceptBuyOnly)
                                {
                                    if (lastSignal.Type == GlobalVar.SignalBuy)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                        WriteSignalLog("큰높이 하방전환 매도신호", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                }
                                else
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("큰높이 하방전환 매도신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }

                            if (curForeInfo.EndY < (m_SignalHighLowInfo.CloseMin))
                            {
                                if (a_AcceptSignal == GlobalVar.AcceptSellOnly)
                                {
                                    if (lastSignal.Type == GlobalVar.SignalBuy)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                        WriteSignalLog("큰높이 하방돌파 매수신호", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                }
                                else
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("큰높이 하방돌파 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                        }
                    }
                }
                else
                {
                    double lowZoneVal = m_SignalHighLowInfo.LowY + GlobalVar.MinHighLowHeight;
                    double highZoneVal = m_SignalHighLowInfo.HighY - GlobalVar.MinHighLowHeight;
                    if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceUp)
                    {
                        if (curWave.LowY <= firstLowY && curWave.LowY < m_ETHighLowSignalManager.LowLimit && curForeInfo.EndY > lowZoneVal)
                        {
                            if (a_AcceptSignal == GlobalVar.AcceptSellOnly)
                            {
                                if (lastSignal.Type == GlobalVar.SignalSell)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("작은 높이 상방전환 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                WriteSignalLog("작은 높이 상방전환 매수신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                        if (curForeInfo.EndY > (m_SignalHighLowInfo.CloseMax))
                        {
                            if (a_AcceptSignal == GlobalVar.AcceptSellOnly)
                            {
                                if (lastSignal.Type == GlobalVar.SignalSell)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("작은 높이 상방돌파 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                WriteSignalLog("작은 높이 상방돌파 매수신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                    }
                    else if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceDown)
                    {
                        if (curWave.HighY >= firstHighY && curWave.HighY > m_ETHighLowSignalManager.HighLimit && curForeInfo.EndY < highZoneVal)
                        {
                            if (a_AcceptSignal == GlobalVar.AcceptBuyOnly)
                            {
                                if (lastSignal.Type == GlobalVar.SignalBuy)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("작은 높이 하방전환 매도신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                WriteSignalLog("작은 높이 하방전환 매도신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                        if (curForeInfo.EndY < (m_SignalHighLowInfo.CloseMin))
                        {
                            if (a_AcceptSignal == GlobalVar.AcceptBuyOnly)
                            {
                                if (lastSignal.Type == GlobalVar.SignalBuy)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                                    WriteSignalLog("작은 높이 하방돌파 매도신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                                WriteSignalLog("작은 높이 하방돌파 매도신호", a_LogFileName, a_CurSignal);
                                return a_CurSignal;
                            }
                        }
                    }
                }
            }
            return null;
        }

        // 값에 의해서 신호를 전환한다.
        public EasyTrader.Signal.PriceSignal FindSignalJisuWave(PriceSignalList a_SignalList, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            int signalVal = GlobalVar.SignalNone;

            if (m_ETHighLowSignalManager == null || m_ETWaveSignalManager == null)
                return null;
            double curVal = GetCurVal(m_CurIndex);
            if (curVal == 0.0)
                return null;
            ForecastingInfo curForeInfo = m_ETWaveSignalManager.ForeInfo;
            // 신호를 발생시킬 고저 폭을 구한다.
            //HighLowInfo m_HighLowInfo = m_ETWaveSignalManager.FindSignalHeightInfo(a_CurIndex);
            // 현재 파동을 가져온다.
            EasyTrader.Wave.PriceWave curWave = m_ETWaveSignalManager.EasyTraderWaveManager.GetCurWave(m_CurIndex);
            // 이전에 발생한 신호를 가져온다.
            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal(a_SignalList);
            if (curForeInfo == null || m_SignalHighLowInfo == null || curWave == null || lastSignal == null)
                return null;
            // 신호가 발생한 파동을 가져온다.
            EasyTrader.Wave.PriceWave lastSigWave = m_ETWaveSignalManager.FindArrangeWave(lastSignal.X);
            if (lastSigWave == null)
                return null;

            // 신호가 발생한 파동과 현재 파동이 같은 파동인지 조사한다.
            bool sameWaveOrder = EasyTrader.Wave.WaveManager.IsSameWave(lastSigWave, curWave);
            // 파동의 최소, 최대값을 구한다.
            m_ETWaveSignalManager.FindWaveHighLow(curWave);
            m_ETWaveSignalManager.FindWaveHighLow(lastSigWave);
            // 신호가 발생된 이후의 예측값을 구한다.
            if (sameWaveOrder == true)
                m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_CurWaveForeInfo, "종가", GlobalVar.RegressionType, Math.Max(0, curWave.StartX - GlobalVar.ForecastCompLen), curWave.EndX - 1, false);
            else
                m_ETWaveSignalManager.GetForecastingInfoByBeginEnd(m_CurWaveForeInfo, "종가", GlobalVar.RegressionType, Math.Max(0, lastSigWave.EndX - GlobalVar.ForecastCompLen), m_CurIndex, false);

            /*
            // 예측 파동 최소 높이에서는 반응하지 않음
            if (m_CurWaveForeInfo.Height() <= GlobalVar.MinForeInfoHeight)
            {
                WriteSignalLog(a_CurIndex, signalVal, "현재 예측파동 높이가 너무 낮아 신호거부");
                return signalVal;
            }*/


#region SignalFiltering By Value
            string strLog = "";

            // 최소 높이에서는 반응하지 않음
            if (m_SignalHighLowInfo.HighLowHeight() < GlobalVar.MinSignalHeight)
            {
                strLog = "현재 진폭 : " + m_SignalHighLowInfo.HighLowHeight().ToString("F2");
                strLog += ", 현재 진폭이 신호발생 최소 높이보다 낮아 신호거부";
                WriteErrorLog(m_CurIndex, strLog);
                return null;
            }
#endregion

            if (lastSignal.Type == GlobalVar.SignalBuy)
            {
                double lastLowY = lastSignal.SignalMin;
                double lastCloseLowY = lastSignal.SignalCloseMin;
                double midVal = (lastLowY + lastCloseLowY) / 2.0;
                if (m_CurWave.Slope == GlobalVar.PriceDown && curForeInfo.EndY < midVal)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && JisuWaveSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("돌파매도", a_CurSignal);
                    return a_CurSignal;
                }
            }
            else if (lastSignal.Type == GlobalVar.SignalSell)
            {
                double lasthighY = lastSignal.SignalMax;
                double lastClosehighY = lastSignal.SignalCloseMax;
                double midVal = (lasthighY + lastClosehighY) / 2.0;
                if (m_CurWave.Slope == GlobalVar.PriceUp && curForeInfo.EndY > midVal)
                {
                    if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && JisuWaveSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                    {
                        return null;
                    }
                    SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("돌파매수", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }

            double dayAmp = m_ETHighLowSignalManager.DayHigh - m_ETHighLowSignalManager.DayLow;
            if (dayAmp < 0.8)
                return null;

            double highLimit = m_SignalHighLowInfo.CloseMax - JisuWaveSysVar.MinTurnHeight;
            double lowLimit = m_SignalHighLowInfo.CloseMin + JisuWaveSysVar.MinTurnHeight;
            double lowRootLimit = m_SignalHighLowInfo.LowY + GlobalVar.WaveRootLimit;
            double highRootlLimit = m_SignalHighLowInfo.HighY - GlobalVar.WaveRootLimit;
            if (m_CurWave.Height() >= GlobalVar.FirstMinHeight)
            {
                if (m_CurWave.Slope == GlobalVar.PriceUp)
                {
                    if (m_CurVal >= lowLimit && m_CurWave.LowY <= lowRootLimit)
                    {
                        if (lastSignal.Type != GlobalVar.SignalBuy)
                        {
                            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && JisuWaveSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                            {
                                return null;
                            }
                            SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                            WriteSignalLog("상방전환 매수신호", a_LogFileName, a_CurSignal);
                            return a_CurSignal;
                        }
                    }
                }
                else if (m_CurWave.Slope == GlobalVar.PriceDown)
                {
                    if (m_CurVal <= highLimit && m_CurWave.HighY >= highRootlLimit)
                    {
                        if (lastSignal.Type != GlobalVar.SignalSell)
                        {
                            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal && JisuWaveSysVar.EnterByClose == true && m_EasyTraderDataSet.ServerSec < 58)
                            {
                                return null;
                            }
                            SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                            WriteSignalLog("하방전환 매도신호", a_LogFileName, a_CurSignal);
                            return a_CurSignal;
                        }
                    }
                }
            }
            return null;
        }

        // 값에 의해서 신호를 전환한다.
        public EasyTrader.Signal.PriceSignal FindSignalByLiquid(int a_CurIndex, PriceSignalList a_GuideSignalList, int a_AcceptSignal, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal, PriceSignalList a_SignalList)
        {
            int signalVal = GlobalVar.SignalNone;
            double curVal = GetCurVal(a_CurIndex);
            ForecastingInfo curForeInfo = m_ETWaveSignalManager.ForeInfo;
            // 현재 파동을 가져온다.
            EasyTrader.Wave.PriceWave curWave = m_ETWaveSignalManager.EasyTraderWaveManager.GetCurWave(a_CurIndex);
            EasyTrader.Wave.PriceWave curShortWave = m_ETWaveSignalManager.EasyTraderWaveManager.GetCurFirstWave(a_CurIndex);
            // 이전에 발생한 신호를 가져온다.
            EasyTrader.Signal.PriceSignal lastGuideSignal = GetLastSignal(a_GuideSignalList);
            if (m_ETHighLowSignalManager == null || m_ETWaveSignalManager == null || curForeInfo == null || 
                m_SignalHighLowInfo == null/* || curWave == null*/ || lastGuideSignal == null || curVal == 0.0 || curShortWave == null)
                return null;

            double curDayAmp = m_ETWaveSignalManager.GetDayCloseAmp(a_CurIndex);
            double preDayAmp = m_ETWaveSignalManager.GetDayCloseAmp(a_CurIndex - 1);
            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal(a_SignalList);
            // 여기서 청산 신호를 내준다.
            if (lastSignal != null)
            {
                double dayHigh = m_ETHighLowSignalManager.DayCloseMax;
                double startVal = m_CurVal;
                if (curShortWave.Slope == GlobalVar.PriceUp)
                    startVal = curShortWave.EndY;
                else
                    startVal = curShortWave.StartY;
                m_CrossCount = m_ETWaveSignalManager.EasyTraderWaveManager.GetWaveCrossDownCount(a_CurIndex, dayHigh, 0.05, startVal, 360);
                if (m_CrossCount >= 7)
                {
                    int i = 0;
                    i = i + 1;
                }
                // 파동의 최소, 최대값을 구한다.
                m_ETWaveSignalManager.FindWaveHighLow(curShortWave);
                if (lastSignal.Type == GlobalVar.SignalBuy)
                {
                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitBuy, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("매수청산", a_CurSignal);
                    return a_CurSignal;
                }
                else if (lastSignal.Type == GlobalVar.SignalSell)
                {
                    SetStateInfo(a_CurIndex, GlobalVar.SignalExitSell, GlobalVar.SignalStateOver, ref a_CurSignal);
                    WriteSignalLog("매도청산", a_CurSignal);
                    return a_CurSignal;
                }
            }

            // 여기서 진입신호를 내준다.
            if (lastGuideSignal.Type == GlobalVar.SignalBuy)
            {
                if (curWave.Slope == GlobalVar.PriceUp)
                {
                    if (lastSignal == null)
                    {
                        SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst, ref a_CurSignal);
                        WriteSignalLog("첫신호매수", a_CurSignal);
                        return a_CurSignal;
                    }
                    else
                    {
                        if (lastGuideSignal.SignalState == GlobalVar.SignalStateTrans)
                        {
                            if (lastGuideSignal.X == a_CurIndex)
                            {
                                if (lastSignal.Type != GlobalVar.SignalBuy)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                    WriteSignalLog("상방전환 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                double highLimit = lastGuideSignal.SignalMax + 0.2;
                                double lowLimit = lastGuideSignal.SignalMin + 0.6;
                                //if (curVal >= highLimit  || curVal <= lowLimit)
                                //{
                                    if (lastSignal.Type != GlobalVar.SignalBuy)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                        WriteSignalLog("상방전환 매수신호", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                //}
                            }
                        }
                        else
                        {
                            double highLimit = lastGuideSignal.SignalCloseMax + 0.2;
                            double lowLimit = m_SignalHighLowInfo.CloseMax - 0.1;
                            if (curVal < lowLimit)
                            {
                                if (lastSignal.Type != GlobalVar.SignalBuy && curShortWave.Slope == GlobalVar.PriceUp)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                    WriteSignalLog("상방전환 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else if (curVal >= highLimit)
                            {
                                if (lastSignal.Type != GlobalVar.SignalBuy)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                    WriteSignalLog("상방전환 매수신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                        }
                    }
                }
            }
            else if (lastGuideSignal.Type == GlobalVar.SignalSell)
            {
                if (curWave.Slope == GlobalVar.PriceDown)
                {
                    if (lastSignal == null)
                    {
                        SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst, ref a_CurSignal);
                        WriteSignalLog("첫신호매도", lastGuideSignal);
                        return a_CurSignal;
                    }
                    else
                    {
                        if (lastGuideSignal.SignalState == GlobalVar.SignalStateTrans)
                        {
                            if (lastGuideSignal.X == a_CurIndex)
                            {
                                if (lastSignal.Type != GlobalVar.SignalSell)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                    WriteSignalLog("하방전환 매도신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else
                            {
                                double lowLimit = lastGuideSignal.SignalMin - 0.2;
                                double highLimit = lastGuideSignal.SignalMax - 0.6;
                                //if (curVal <= lowLimit || curVal >= highLimit)
                                //{
                                    if (lastSignal.Type != GlobalVar.SignalSell)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                        WriteSignalLog("하방전환 매도신호", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                //}
                            }
                        }
                        else
                        {
                            double highLimit = m_SignalHighLowInfo.CloseMin + 0.1;
                            double lowLimit = lastGuideSignal.SignalCloseMin - 0.2;
                            if (curVal > highLimit)
                            {
                                if (lastSignal.Type != GlobalVar.SignalSell && curShortWave.Slope == GlobalVar.PriceDown)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                    WriteSignalLog("하방전환 매도신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                            else if (curVal <= lowLimit)
                            {
                                if (lastSignal.Type != GlobalVar.SignalSell)
                                {
                                    SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateTrans, ref a_CurSignal);
                                    WriteSignalLog("하방전환 매도신호", a_LogFileName, a_CurSignal);
                                    return a_CurSignal;
                                }
                            }
                        }
                    }
                }
            }
            
            return null;
        }
        
        // 기준파를 중심으로 퍼센트를 계산한다.
        public double CalcReverseRatio(int a_CurIndex)
        {
            if (m_SignalWave == null)
                return 0.0;

            double curVal = GetCurVal(a_CurIndex);
            if (curVal == 0.0)
                return 0.0;

            double waveHeight = Math.Abs(m_SignalWave.StartY - m_SignalWave.EndY);

            double deltaPrice = Math.Abs(curVal - m_SignalWave.EndY);
            double ratio = deltaPrice / waveHeight * 100;

            return ratio;
        }

        private void AddSignalWave(EasyTrader.Wave.PriceWave a_Wave)
        {
            if (a_Wave == null)
                return;
            m_SignalWaveList.Add(a_Wave);
        }

        // 이 함수는 새로운 기준파를 보고 새로운 신호를 탐색한다.
        // 기준파와 현재 파동이 방향이 같고 길이가 늘어날때 기준파의 방향으로 신호를 낸다.
        // 기준파가 이전 기준파와 방향이 다를 때 신호를 낸다.
        // 기준파의 길이가 바뀌었을 때에는 길이를 수정해 주고 
        // 기준파의 방향이 바뀌었을 때에는 이전의 기준파를 기준파 목록에 더해준다.
        private int FindSignalByNewSignalWave(EasyTrader.Wave.PriceWave a_CurWave, EasyTrader.Wave.PriceWave a_SignalWave)
        {
            int signal = GlobalVar.SignalNone;
            if (a_CurWave == null || a_SignalWave == null)
                return signal;

            // 신호 파동이 비어 있을 때는 추가만 하고 바로 반환한다.
            // 실제 신호는 파동에서 추출한다.
            if (m_SignalWaveList.Count == 0)
            {
                // 새로운 기준파 등록
                AddSignalWave(a_SignalWave);
                return signal;
            }

            EasyTrader.Wave.PriceWave lastSignalWave = m_SignalWaveList[m_SignalWaveList.Count - 1];
            // 이전 기준파와 방향이 같을 때
            if (lastSignalWave.Slope == a_SignalWave.Slope)
            {
                // 같은 방향이지만 기존의 기준파와는 다른 기준파가 생길경우 기준파 쪽으로 신호를 내준다.
                if (lastSignalWave.StartX < a_SignalWave.StartX)
                {
                    if (a_CurWave.Slope == GlobalVar.PriceUp)
                    {
                        signal = GlobalVar.SignalBuy;
                        WriteSignalLog(GlobalVar.DayIndex() + 1, signal, "기존의 기준파와 방향이 같지만 새로운 기준파가 생겨 매수->");
                    }
                    else
                    {
                        signal = GlobalVar.SignalSell;
                        WriteSignalLog(GlobalVar.DayIndex() + 1, signal, "기존의 기준파와 방향이 같지만 새로운 기준파가 생겨 매도->");
                    }
                    // 새로운 기준파 등록
                    AddSignalWave(a_SignalWave);
                    return signal;
                }
                else
                {
                    // 현재파와 방향이 같고 이전 기준파보다 길이가 더 길어질 때 기준파 쪽으로 신호를 낸다.
                    if (a_CurWave.Slope == a_SignalWave.Slope && a_SignalWave.Height() > lastSignalWave.Height())
                    {
                        if (a_CurWave.Slope == GlobalVar.PriceUp)
                        {
                            signal = GlobalVar.SignalBuy;
                            WriteSignalLog(GlobalVar.DayIndex() + 1, signal, "현재파상승중 기준파길이가 길어져 매수->");
                        }
                        else
                        {
                            signal = GlobalVar.SignalSell;
                            WriteSignalLog(GlobalVar.DayIndex() + 1, signal, "현재파하락중 기준파길이가 길어져 매도->");
                        }

                        // 기존의 기준파 정보를 갱신해 준다.
                        lastSignalWave.EndX = a_SignalWave.EndX;
                        lastSignalWave.EndY = a_SignalWave.EndY;
                        return signal;
                    }
                    else
                        return signal;
                }
            }
            else // 이전 기준파와 방향이 다를 때
            {
                if (a_CurWave.Slope == a_SignalWave.Slope)
                {
                    if (a_CurWave.Slope == GlobalVar.PriceUp)
                    {
                        signal = GlobalVar.SignalBuy;
                        WriteSignalLog(GlobalVar.DayIndex() + 1, signal, "매수 기준파가 새로생겨 매수");
                    }
                    else
                    {
                        signal = GlobalVar.SignalSell;
                        WriteSignalLog(GlobalVar.DayIndex() + 1, signal, "매도 기준파가 새로생겨 매도");
                    }

                    // 새로운 기준파 등록
                    AddSignalWave(a_SignalWave);
                    return signal;
                }
                else
                    return signal;
            }
        }

        // 기준파와 예측지수로 신호를 만들어 낸다.
        public int FindSignalBySTDWave(int a_CurIndex)
        {
            int signal = GlobalVar.SignalNone;
            if (m_ETWaveSignalManager == null)
                return signal;
            if (m_ETWaveSignalManager.ForeInfo == null)
                return signal;
            if (m_ETWaveSignalManager.GetArrangedWaveCount() == 1)
                return signal;

            // 신호 파동을 찾는다.
            m_SignalWave = m_ETWaveSignalManager.FindSignalWave();
            if (m_SignalWave == null)
                return signal;
            EasyTrader.Wave.PriceWave curWave = m_ETWaveSignalManager.EasyTraderWaveManager.GetCurWave(a_CurIndex);
            if (curWave == null)
                return signal;

            // 시작점과 끝점을 정렬해 준다.
            m_ETWaveSignalManager.AdjustSignalWave(m_SignalWave);

            // 기준파에 의한 상단하단 경계값 계산
            CalcHighLowZoneByWave(a_CurIndex, m_SignalWave, GlobalVar.StandardWaveHighLowPercent);

            // 신호 필터링이 되어 있는지 점검한다.
            if (GlobalVar.AfterFirstSignalFilter == true)
            {
                // 신호 필터링 값들
                // 주체별 포지션 필터링
                bool subjectSel = false;
                // 개인 옵션 필터링
                if (GlobalVar.OptionExtremeCase == true && IsOptionPersonExtremeCase() != true)
                    return signal;

                // 코스피 개인,기관,외국인 방향에 의한 필터링
                int direction = GlobalVar.PriceFlat;
                if (GlobalVar.SubjectSelection == 1)
                {
                    subjectSel = IsKospiForeignOrganSameDirection(ref direction);
                    if (subjectSel != true)
                        return signal;
                }
                else if (GlobalVar.SubjectSelection == 2)
                {
                    subjectSel = IsKospiForeignOrganProgramSameDirection(ref direction);
                    if (subjectSel != true)
                        return signal;
                }
                else if (GlobalVar.SubjectSelection == 3)
                {
                    subjectSel = IsKospiForeignOrganProgramFutureForeignSameDirection(ref direction);
                    if (subjectSel != true)
                        return signal;
                }

                EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal();

                // 신호 필터링은 정식 신호 파동이 생긴이후에 두번째 신호부터 이루어 진다.
                if (m_SignalWave.Height() >= GlobalVar.SignalWaveHeight && lastSignal != null)
                {
                    // 최소각도 필터링
                    if (m_FutOptPriceInfo.Height() <= 0.2)
                        return signal;
                    double totalPercent = Math.Abs(m_TotalSignal);
                    if (totalPercent < 20.0)
                        return signal;
                    // 마지막 신호가 전체 신호와 방향이 같고 정해진 퍼센트를 넘을 때는 모든 신호를 무시한다.
                    if (lastSignal.Type == GlobalVar.SignalBuy && m_TotalSignal > 0 && totalPercent >= GlobalVar.MinSignalPercent)
                        return signal;
                    if (lastSignal.Type == GlobalVar.SignalSell && m_TotalSignal < 0 && totalPercent >= GlobalVar.MinSignalPercent)
                        return signal;

                    // 최소 호가 건수 필터링
                    if (GlobalVar.MinDeltaBuySellEnable == true && DeltaHogaBuySell < GlobalVar.MinDeltaBuySell)
                        return signal;
                    // 최소 호가 잔량 필터링
                    if (GlobalVar.MinDeltaBidsAsksEnable == true && DeltaHogaBidsAsks < GlobalVar.MinDeltaBidsAsks)
                        return signal;
                    // 최대 호가 건수 필터링
                    if (GlobalVar.MaxDeltaBuySellEnable == true && DeltaHogaBuySell > GlobalVar.MaxDeltaBuySell)
                        return signal;
                    // 최대 호가 잔량 필터링
                    if (GlobalVar.MaxDeltaBidsAsksEnable == true && DeltaHogaBidsAsks > GlobalVar.MaxDeltaBidsAsks)
                        return signal;
                }
            }
            

            // 새로운 기준파에 의한 신호를 검출한다.
            signal = FindSignalByNewSignalWave(curWave, m_SignalWave);
            // 신호가 발생했다면 그냥 신호를 내보낸다.
            if (signal != GlobalVar.SignalNone)
                return signal;

            double curVal = GetCurVal(a_CurIndex);
            if (curVal == 0.0)
                return signal;
            
            double waveHeight = m_SignalWave.Height();
            
            ForecastingInfo curForeInfo = m_ETWaveSignalManager.ForeInfo;
            double deltaFore = curForeInfo.EndY - curForeInfo.StartY;
            int foreSlope = GlobalVar.PriceFlat;
            if (deltaFore > 0)
                foreSlope = GlobalVar.PriceUp;
            else if (deltaFore < 0)
                foreSlope = GlobalVar.PriceDown;
            // 첫번째 신호가 잘 못 나왔을 경우에 대한 처리
            // 현재 파동과 신호가 다르다면 수정을 해준다.
            if (m_PriceSignalList.Count == 1)
            {
                EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal();
                if (curWave.Slope == m_SignalWave.Slope && lastSignal.X <= curWave.StartX)
                {
                    if (m_SignalWave.Slope == GlobalVar.PriceUp && lastSignal.Type == GlobalVar.OrderSell)
                    {
                        signal = GlobalVar.SignalBuy;
                        WriteSignalLog(a_CurIndex, signal, "진입신호 및 첫신호 수정신호->");
                        return signal;
                    }

                    if (m_SignalWave.Slope == GlobalVar.PriceDown && lastSignal.Type == GlobalVar.OrderBuy)
                    {
                        signal = GlobalVar.SignalSell;
                        WriteSignalLog(a_CurIndex, signal, "진입신호 및 첫신호 수정신호->");
                        return signal;
                    }
                }
            }

            double maxVal = Math.Max(m_SignalWave.StartY, m_SignalWave.EndY);
            double minVal = Math.Min(m_SignalWave.StartY, m_SignalWave.EndY);
            if (waveHeight >= GlobalVar.SignalWaveHeight)
            {
                if (m_SignalWave.Slope == GlobalVar.PriceUp)
                {
                    // 현재파동과 기준파가 서로 반대 방향일 때
                    if (m_SignalWave.Slope != curWave.Slope)
                    {
                        if (curForeInfo.EndY <= m_WaveHighZoneVal || curForeInfo.EndY <= m_ETHighLowSignalManager.HighLimit)
                        {
                            signal = GlobalVar.SignalSell;
                            WriteSignalLog(a_CurIndex, signal, "기준파정상높이 하방전환신호->");
                        }
                    }
                    else // 현재파동과 기준파가 서로 같은 방향일 때
                    {
                        if (curVal > maxVal || curVal > m_ETHighLowSignalManager.DayHigh)
                        {
                            signal = GlobalVar.SignalBuy;
                            WriteSignalLog(a_CurIndex, signal, "기준파정상높이 상방돌파신호->");
                        }
                    }
                }
                else if (m_SignalWave.Slope == GlobalVar.PriceDown)
                {
                    if (m_SignalWave.Slope != curWave.Slope)
                    {
                        if (curForeInfo.EndY >= m_WaveLowZoneVal || curForeInfo.EndY >= m_ETHighLowSignalManager.LowLimit)
                        {
                            signal = GlobalVar.SignalBuy;
                            WriteSignalLog(a_CurIndex, signal, "기준파정상높이 상방전환신호->");
                        }
                    }
                    else
                    {
                        if (curVal < minVal || curVal < m_ETHighLowSignalManager.DayLow)
                        {
                            signal = GlobalVar.SignalSell;
                            WriteSignalLog(a_CurIndex, signal, "기준파정상높이 하방돌파신호->");
                        }
                    }
                }
            }
            else
            {
                if (m_SignalWave.Slope == GlobalVar.PriceUp)
                {
                    double highZoneVal = maxVal - GlobalVar.SignalWaveHeight * GlobalVar.StandardWaveHighLowPercent;
                    if (m_SignalWave.Slope != curWave.Slope)
                    {
                        if (m_ETWaveSignalManager.GetShortWaveCount() <= 2 && curForeInfo.EndY <= highZoneVal)
                        {
                            signal = GlobalVar.SignalSell;
                            WriteSignalLog(a_CurIndex, signal, "기준파최소높이 하방전환신호->");
                        }
                    }
                    else
                    {
                        if (curForeInfo.EndY >= maxVal)
                        {
                            signal = GlobalVar.SignalBuy;
                            WriteSignalLog(a_CurIndex, signal, "기준파최소높이 상방돌파신호->");
                        }
                    }
                }
                else if (m_SignalWave.Slope == GlobalVar.PriceDown)
                {
                    double lowZoneVal = minVal + GlobalVar.SignalWaveHeight * GlobalVar.StandardWaveHighLowPercent;
                    if (m_SignalWave.Slope != curWave.Slope)
                    {
                        if (m_ETWaveSignalManager.GetShortWaveCount() <= 2 && curForeInfo.EndY >= lowZoneVal)
                        {
                            signal = GlobalVar.SignalBuy;
                            WriteSignalLog(a_CurIndex, signal, "기준파최소높이 상방전환신호->");
                        }
                    }
                    else
                    {
                        if (curForeInfo.EndY <= minVal)
                        {
                            signal = GlobalVar.SignalSell;
                            WriteSignalLog(a_CurIndex, signal, "기준파최소높이 하방돌파신호->");
                        }
                    }
                }
            }

            return signal;
        }

        public void WriteSignalLog(int a_CurIndex, int a_Signal, string a_HeaderMsg)
        {
            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal();
            if (lastSignal != null && lastSignal.Type == a_Signal)
                return;

            string logMsg = a_HeaderMsg;
            logMsg += ", 인덱스 :" + a_CurIndex.ToString();
            logMsg += ", 현재시간 : " + GlobalVar.TimeToIntEx().ToString();
            double curVal = GetCurVal(a_CurIndex);
            logMsg += ", 현재 가격 : " + curVal.ToString("F2");
            logMsg += ", 신호종류 : ";
            if (a_Signal == GlobalVar.SignalNone)
            {
                logMsg += "신호없음";
            }
            else if (a_Signal == GlobalVar.SignalSell)
            {
                logMsg += "매도";
            }
            else if (a_Signal == GlobalVar.SignalBuy)
            {
                logMsg += "매수";
            }
            else
            {
                logMsg += "알수없음";
            }

            GlobalVar.WriteLog(logMsg);
        }

        public void WriteSignalLog(int a_CurIndex, int a_Signal, string a_HeaderMsg, string a_FileName)
        {
            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal();
            if (lastSignal != null && lastSignal.Type == a_Signal)
                return;

            string logMsg = a_HeaderMsg;
            logMsg += ", 인덱스 :" + a_CurIndex.ToString();
            logMsg += ", 현재시간 : " + GlobalVar.TimeToIntEx().ToString();
            double curVal = GetCurVal(a_CurIndex);
            logMsg += ", 현재 가격 : " + curVal.ToString("F2");
            logMsg += ", 신호종류 : ";
            if (a_Signal == GlobalVar.SignalNone)
            {
                logMsg += "신호없음";
            }
            else if (a_Signal == GlobalVar.SignalSell)
            {
                logMsg += "매도";
            }
            else if (a_Signal == GlobalVar.SignalBuy)
            {
                logMsg += "매수";
            }
            else
            {
                logMsg += "알수없음";
            }

            GlobalVar.WriteLogWithFileName(logMsg, a_FileName);
        }

        public void WriteSignalLog(int a_CurIndex, int a_Signal, int a_SignalState, string a_HeaderMsg)
        {
            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal();
            //if (lastSignal != null && lastSignal.Type == a_Signal)
            //    return;

            string logMsg = a_HeaderMsg;
            logMsg += ", 인덱스 :" + a_CurIndex.ToString();
            logMsg += ", 현재시간 : " + GlobalVar.TimeToIntEx().ToString();
            double curVal = GetCurVal(a_CurIndex);
            logMsg += ", 현재 가격 : " + curVal.ToString("F2");

            logMsg += ", 현재 고저정보 -- >";
            logMsg += ", 현재높이 StartX :" + m_SignalHighLowInfo.StartX.ToString();
            logMsg += ", 현재높이 EndX :" + m_SignalHighLowInfo.EndX.ToString();
            logMsg += ", 현재높이 HighY : " + m_SignalHighLowInfo.HighY.ToString("F2");
            logMsg += ", 현재높이 LowY : " + m_SignalHighLowInfo.LowY.ToString("F2");

            logMsg += ", 신호상태 : ";
            if (a_SignalState == GlobalVar.SignalStateFirst)
            {
                logMsg += "첫진입신호";
            }
            else if (a_SignalState == GlobalVar.SignalStateTrans)
            {
                logMsg += "전환신호";
            }
            if (a_SignalState == GlobalVar.SignalStateOver)
            {
                logMsg += "돌파신호";
            }
            if (a_SignalState == GlobalVar.SignalStateLiquid)
            {
                logMsg += "청산신호";
            }
            else
            {
                logMsg += "상태없음";
            }

            logMsg += ", 신호종류 : ";
            if (a_Signal == GlobalVar.SignalNone)
            {
                logMsg += "신호없음";
            }
            else if (a_Signal == GlobalVar.SignalSell)
            {
                logMsg += "매도";
            }
            else if (a_Signal == GlobalVar.SignalBuy)
            {
                logMsg += "매수";
            }
            else
            {
                logMsg += "알수없음";
            }

            
            GlobalVar.WriteLog(logMsg);
        }
        // 장시작이후 입문 신호가 나오지 않았을 때 이 신호를 발생한다.
        // 첫신호가 나올 때까지 계속시도한다.
        public int FindFirstSignal(int a_CurIndex, ref int a_SignalState)
        {
            int signalVal = GlobalVar.SignalNone;
            double totalPercent = Math.Abs(m_TotalSignal);
            if (GlobalVar.FirstSignalFilter == true)
            {
                // 신호 필터링 값들
                // 주체별 포지션 필터링
                bool subjectSel = false;
                // 개인 옵션 필터링
                if (GlobalVar.OptionExtremeCase == true && IsOptionPersonExtremeCase() != true)
                    return signalVal;

                // 코스피 개인,기관,외국인 방향에 의한 필터링
                int direction = GlobalVar.PriceFlat;
                if (GlobalVar.SubjectSelection == 1)
                {
                    subjectSel = IsKospiForeignOrganSameDirection(ref direction);
                    if (subjectSel != true)
                        return signalVal;
                }
                else if (GlobalVar.SubjectSelection == 2)
                {
                    subjectSel = IsKospiForeignOrganProgramSameDirection(ref direction);
                    if (subjectSel != true)
                        return signalVal;
                }
                else if (GlobalVar.SubjectSelection == 3)
                {
                    subjectSel = IsKospiForeignOrganProgramFutureForeignSameDirection(ref direction);
                    if (subjectSel != true)
                        return signalVal;
                }

                // 신호 필터링은 정식 신호 파동이 생긴이후에 두번째 신호부터 이루어 진다.
                if (m_SignalWave != null && m_SignalWave.Height() >= GlobalVar.SignalWaveHeight)
                {
                    // 최소 호가 건수 필터링
                    if (GlobalVar.MinDeltaBuySellEnable == true && DeltaHogaBuySell < GlobalVar.MinDeltaBuySell)
                        return signalVal;
                    // 최소 호가 잔량 필터링
                    if (GlobalVar.MinDeltaBidsAsksEnable == true && DeltaHogaBidsAsks < GlobalVar.MinDeltaBidsAsks)
                        return signalVal;
                    // 최대 호가 건수 필터링
                    if (GlobalVar.MaxDeltaBuySellEnable == true && DeltaHogaBuySell > GlobalVar.MaxDeltaBuySell)
                        return signalVal;
                    // 최대 호가 잔량 필터링
                    if (GlobalVar.MaxDeltaBidsAsksEnable == true && DeltaHogaBidsAsks > GlobalVar.MaxDeltaBidsAsks)
                        return signalVal;
                }
            }

            double dailyGap = GetTodayDailyGap();
            int intTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal)
            {
                intTime = GlobalVar.TimeToInt();
            }
            else
            {
                intTime = GlobalVar.DayIndexToTime(a_CurIndex);
            }

            string strLog = "첫신호 조사->";
            strLog += " 현재시간" + GlobalVar.TimeToIntEx().ToString();
            strLog += ", 일간갭" + dailyGap.ToString("F2");
            strLog += ", 전체 퍼센트" + m_TotalSignal.ToString("F2");
            strLog += ", 예측파동 높이" + m_PureForeInfo.Height().ToString("F2");
            if (m_PureForeInfo.Slope() == GlobalVar.PriceUp)
                strLog += ", 현재 파동 방향 : 매수";
            else
                strLog += ", 현재 파동 방향 : 매도";
            strLog += ", 현재 가격" + GetCurVal(a_CurIndex).ToString("F2");
            GlobalVar.WriteLog(strLog);
            int signalStartTime = GlobalVar.TimeToInt(GlobalVar.SignalStartHour, GlobalVar.SignalStartMin);
            if (intTime >= signalStartTime)
            {
                if (m_PureForeInfo.Len() >= GlobalVar.MinForeInfoLen && m_PureForeInfo.Height() >= GlobalVar.MinForeInfoHeight)
                {
                    // 매도, 매수 호가 건수가 발산할 때만 신호를 받을 수 있게 한다.
                    double invdivBuySell = m_ETHogaSignalManager.InvDivBuySell;
                    if (m_PureForeInfo.Slope() == GlobalVar.PriceUp && (invdivBuySell > 0 && invdivBuySell <= 4))
                    {
                        signalVal = GlobalVar.SignalBuy;
                        WriteSignalLog(a_CurIndex, signalVal, "첫신호 매수->");
                        a_SignalState = GlobalVar.SignalStateFirst;
                        return signalVal;
                    }

                    if (m_PureForeInfo.Slope() == GlobalVar.PriceDown && (invdivBuySell < 0 && invdivBuySell >= -4))
                    {
                        signalVal = GlobalVar.SignalSell;
                        WriteSignalLog(a_CurIndex, signalVal, "첫신호 매도->");
                        a_SignalState = GlobalVar.SignalStateFirst;
                        return signalVal;
                    }
                }
            }
            
            return signalVal;
        }


        // 장시작이후 입문 신호가 나오지 않았을 때 이 신호를 발생한다.
        // 첫신호가 나올 때까지 계속시도한다.
        public EasyTrader.Signal.PriceSignal FindFirstSignalByHeight(int a_CurIndex, int a_StartHour, int a_StartMin, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            int signalVal = GlobalVar.SignalNone;
            double totalPercent = Math.Abs(m_TotalSignal);
            int intTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal)
            {
                intTime = GlobalVar.TimeToInt();
            }
            else
            {
                intTime = GlobalVar.DayIndexToTime(a_CurIndex);
            }

            int signalStartTime = GlobalVar.TimeToInt(a_StartHour, a_StartMin);
            if (intTime >= signalStartTime)
            {
                if (m_PureForeInfo.Height() >= GlobalVar.FirstMinHeight)
                {
                    if (m_PureForeInfo.Slope() == GlobalVar.PriceUp)
                    {
                        SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst, ref a_CurSignal);
                        WriteStateLog("매수(초입)", a_LogFileName, a_CurSignal);
                        return a_CurSignal;
                    }

                    if (m_PureForeInfo.Slope() == GlobalVar.PriceDown)
                    {
                        SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst, ref a_CurSignal);
                        WriteStateLog("매도(초입)", a_LogFileName, a_CurSignal);
                        return a_CurSignal;
                    }
                }
            }

            return null;
        }


        public EasyTrader.Signal.PriceSignal FindFirstSignalByHogaDelta(int a_CurIndex, int a_StartHour, int a_StartMin, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            int signalVal = GlobalVar.SignalNone;
            // 실제값으로 차이를 구한다.
            double deltaBuySell = m_HogaBuyInfo.PureEndY - m_HogaSellInfo.PureEndY;
            int intTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal)
            {
                intTime = GlobalVar.TimeToInt();
            }
            else
            {
                intTime = GlobalVar.DayIndexToTime(a_CurIndex);
            }

            int signalStartTime = GlobalVar.TimeToInt(a_StartHour, a_StartMin);
            if (intTime >= signalStartTime)
            {
                if (deltaBuySell > 0)
                {
                    if (m_HogaBuyInfo.PureEndY * GlobalVar.FirstMinPercent > m_HogaSellInfo.PureEndY)
                    {
                        SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst, ref a_CurSignal);
                        WriteStateLog("매수(초입)", a_LogFileName, a_CurSignal);
                        return a_CurSignal;
                    }
                }
                else if (deltaBuySell < 0)
                {
                    if (m_HogaSellInfo.PureEndY * GlobalVar.FirstMinPercent > m_HogaBuyInfo.PureEndY)
                    {
                        SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst, ref a_CurSignal);
                        WriteStateLog("매도(초입)", a_LogFileName, a_CurSignal);
                        return a_CurSignal;
                    }
                }
            }

            return null;
        }

        public EasyTrader.Signal.PriceSignal FindFirstSignalByHogaDeltaNHeight(int a_CurIndex, int a_StartHour, int a_StartMin, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            int signalVal = GlobalVar.SignalNone;
            // 실제값으로 차이를 구한다.
            double deltaBuySell = m_HogaBuyInfo.PureEndY - m_HogaSellInfo.PureEndY;
            int intTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal)
            {
                intTime = GlobalVar.TimeToInt();
            }
            else
            {
                intTime = GlobalVar.DayIndexToTime(a_CurIndex);
            }

            int signalStartTime = GlobalVar.TimeToInt(a_StartHour, a_StartMin);
            if (intTime >= signalStartTime)
            {
                if (deltaBuySell > 0)
                {
                    if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceUp && m_CurWaveForeInfo.Height() >= GlobalVar.FirstMinHeight)
                    {
                        if (m_HogaBuyInfo.PureEndY * GlobalVar.FirstMinPercent > m_HogaSellInfo.PureEndY)
                        {
                            SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst, ref a_CurSignal);
                            WriteStateLog("매수(초입)", a_LogFileName, a_CurSignal);
                            return a_CurSignal;
                        }
                    }
                }
                else if (deltaBuySell < 0)
                {
                    if (m_CurWaveForeInfo.Slope() == GlobalVar.PriceDown && m_CurWaveForeInfo.Height() >= GlobalVar.FirstMinHeight)
                    {
                        if (m_HogaSellInfo.PureEndY * GlobalVar.FirstMinPercent > m_HogaBuyInfo.PureEndY)
                        {
                            SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst, ref a_CurSignal);
                            WriteStateLog("매도(초입)", a_LogFileName, a_CurSignal);
                            return a_CurSignal;
                        }
                    }
                }
            }

            return null;
        }

        public EasyTrader.Signal.PriceSignal FindFirstSignalByWaveCount(int a_CurIndex, int a_StartHour, int a_StartMin, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            int signalVal = GlobalVar.SignalNone;
            if (m_CurWave == null)
                return null;
            if (m_ETWaveSignalManager.GetArrangedWaveCount() < GlobalVar.FirstWave)
                return null;

            int intTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal)
            {
                intTime = GlobalVar.TimeToInt();
            }
            else
            {
                intTime = GlobalVar.DayIndexToTime(a_CurIndex);
            }

            int signalStartTime = GlobalVar.TimeToInt(a_StartHour, a_StartMin);
            if (intTime >= signalStartTime)
            {
                if (m_CurWave.Slope == GlobalVar.PriceUp)
                {
                    SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst, ref a_CurSignal);
                    WriteStateLog("매수(초입)", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
                else if (m_CurWave.Slope == GlobalVar.PriceDown)
                {
                    SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst, ref a_CurSignal);
                    WriteStateLog("매도(초입)", a_LogFileName, a_CurSignal);
                    return a_CurSignal;
                }
            }

            return null;
        }

        public EasyTrader.Signal.PriceSignal FindFirstSignalByWaveCountNHeight(int a_CurIndex, int a_StartHour, int a_StartMin, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            int signalVal = GlobalVar.SignalNone;
            if (m_CurWave == null)
                return null;
            if (m_ETWaveSignalManager.GetArrangedWaveCount() < GlobalVar.FirstWave)
                return null;

            int intTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal)
            {
                intTime = GlobalVar.TimeToInt();
            }
            else
            {
                intTime = GlobalVar.DayIndexToTime(a_CurIndex);
            }

            int signalStartTime = GlobalVar.TimeToInt(a_StartHour, a_StartMin);
            if (intTime >= signalStartTime)
            {
                if (m_CurWave.Slope == GlobalVar.PriceUp)
                {
                    if (m_CurWaveForeInfo.Height() >= GlobalVar.FirstMinHeight)
                    {
                        SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst, ref a_CurSignal);
                        WriteStateLog("매수(초입)", a_LogFileName, a_CurSignal);
                        return a_CurSignal;
                    }
                }
                else if (m_CurWave.Slope == GlobalVar.PriceDown)
                {
                    if (m_CurWaveForeInfo.Height() >= GlobalVar.FirstMinHeight)
                    {
                        SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst, ref a_CurSignal);
                        WriteStateLog("매도(초입)", a_LogFileName, a_CurSignal);
                        return a_CurSignal;
                    }
                }
            }

            return null;
        }


        public EasyTrader.Signal.PriceSignal FindFirstSignal()
        {
            double totalPercent = Math.Abs(m_TotalSignal);
            if (GlobalVar.FirstSignalFilter == true)
            {
                // 신호 필터링 값들
                // 주체별 포지션 필터링
                bool subjectSel = false;
                // 개인 옵션 필터링
                if (GlobalVar.OptionExtremeCase == true && IsOptionPersonExtremeCase() != true)
                    return null;

                // 코스피 개인,기관,외국인 방향에 의한 필터링
                int direction = GlobalVar.PriceFlat;
                if (GlobalVar.SubjectSelection == 1)
                {
                    subjectSel = IsKospiForeignOrganSameDirection(ref direction);
                    if (subjectSel != true)
                        return null;
                }
                else if (GlobalVar.SubjectSelection == 2)
                {
                    subjectSel = IsKospiForeignOrganProgramSameDirection(ref direction);
                    if (subjectSel != true)
                        return null;
                }
                else if (GlobalVar.SubjectSelection == 3)
                {
                    subjectSel = IsKospiForeignOrganProgramFutureForeignSameDirection(ref direction);
                    if (subjectSel != true)
                        return null;
                }

                // 신호 필터링은 정식 신호 파동이 생긴이후에 두번째 신호부터 이루어 진다.
                if (m_SignalWave != null && m_SignalWave.Height() >= GlobalVar.SignalWaveHeight)
                {
                    // 최소 호가 건수 필터링
                    if (GlobalVar.MinDeltaBuySellEnable == true && DeltaHogaBuySell < GlobalVar.MinDeltaBuySell)
                        return null;
                    // 최소 호가 잔량 필터링
                    if (GlobalVar.MinDeltaBidsAsksEnable == true && DeltaHogaBidsAsks < GlobalVar.MinDeltaBidsAsks)
                        return null;
                    // 최대 호가 건수 필터링
                    if (GlobalVar.MaxDeltaBuySellEnable == true && DeltaHogaBuySell > GlobalVar.MaxDeltaBuySell)
                        return null;
                    // 최대 호가 잔량 필터링
                    if (GlobalVar.MaxDeltaBidsAsksEnable == true && DeltaHogaBidsAsks > GlobalVar.MaxDeltaBidsAsks)
                        return null;
                }
            }

            if (m_CurWave == null)
                return null;
            double dailyGap = GetTodayDailyGap();
            int intTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal)
            {
                intTime = GlobalVar.TimeToInt();
            }
            else
            {
                intTime = GlobalVar.DayIndexToTime(m_CurIndex);
            }

            // 매도, 매수 호가 건수가 발산할 때만 신호를 받을 수 있게 한다.
            double invdivBuySell = m_ETHogaSignalManager.InvDivBuySell;
            int signalStartTime = GlobalVar.TimeToInt(GlobalVar.SignalStartHour, GlobalVar.SignalStartMin);
            if (intTime >= signalStartTime && m_PureForeInfo.Height() >= GlobalVar.MinHogaFirstMinHeight)
            {
                if (m_PureForeInfo.Slope() == GlobalVar.PriceUp)
                {
                    switch (Convert.ToInt32(invdivBuySell))
                    {
                        // 기울기가 서로 다른 경우
                        case 1:
                        case 3:
                        case 6:
                            {
                                if (DeltaHogaBuySell >= GlobalVar.DivMinHogaDelta)
                                {
                                    if (invdivBuySell > 0)
                                    {
                                        if (m_CurWave.Slope == GlobalVar.PriceUp)
                                        {
                                            SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst);
                                            WriteSignalLog("첫신호매수", m_CurSignal);
                                            return m_CurSignal;
                                        }
                                    }
                                    else if (invdivBuySell < 0)
                                    {
                                        if (m_CurWave.Slope == GlobalVar.PriceDown)
                                        {
                                            SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst);
                                            WriteSignalLog("첫신호매도", m_CurSignal);
                                            return m_CurSignal;
                                        }
                                    }
                                }
                                break;
                            }
                        // 기울기가 서로 같은 경우
                        case 2:
                        case 4:
                        case 5:
                        case 7:
                        case 8:
                        case 9:
                            {
                                if (DeltaHogaBuySell >= GlobalVar.InvMinHogaDelta)
                                {
                                    double deltaAngle = Math.Abs(m_HogaBuyInfo.Angle - m_HogaSellInfo.Angle);
                                    // 각도 차이가 일정값을 넘을 때만 진입을 시도한다.
                                    if (deltaAngle > GlobalVar.MinHogaAngleDelta)
                                    {
                                        if (invdivBuySell > 0)
                                        {
                                            if (m_CurWave.Slope == GlobalVar.PriceUp)
                                            {
                                                SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst);
                                                WriteSignalLog("첫신호매수", m_CurSignal);
                                                return m_CurSignal;
                                            }
                                        }
                                        else if (invdivBuySell < 0)
                                        {
                                            if (m_CurWave.Slope == GlobalVar.PriceDown)
                                            {
                                                SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst);
                                                WriteSignalLog("첫신호매도", m_CurSignal);
                                                return m_CurSignal;
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                        default :
                            break;
                    }
                }
                else if (m_PureForeInfo.Slope() == GlobalVar.PriceDown)
                {
                    switch (Convert.ToInt32(invdivBuySell))
                    {
                        // 기울기가 서로 다른 경우
                        case -1:
                        case -3:
                        case -6:
                            {
                                if (DeltaHogaBuySell >= GlobalVar.DivMinHogaDelta)
                                {
                                    if (invdivBuySell > 0)
                                    {
                                        if (m_CurWave.Slope == GlobalVar.PriceUp)
                                        {
                                            SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst);
                                            WriteSignalLog("첫신호매수", m_CurSignal);
                                            return m_CurSignal;
                                        }
                                    }
                                    else if (invdivBuySell < 0)
                                    {
                                        if (m_CurWave.Slope == GlobalVar.PriceDown)
                                        {
                                            SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst);
                                            WriteSignalLog("첫신호매도", m_CurSignal);
                                            return m_CurSignal;
                                        }
                                    }
                                }
                                break;
                            }
                        // 기울기가 서로 같은 경우
                        case -2:
                        case -4:
                        case -5:
                        case -7:
                        case -8:
                        case -9:
                            {
                                if (DeltaHogaBuySell >= GlobalVar.InvMinHogaDelta)
                                {
                                    double deltaAngle = Math.Abs(m_HogaBuyInfo.Angle - m_HogaSellInfo.Angle);
                                    // 각도 차이가 일정값을 넘을 때만 진입을 시도한다.
                                    if (deltaAngle > GlobalVar.MinHogaAngleDelta)
                                    {
                                        if (invdivBuySell > 0)
                                        {
                                            if (m_CurWave.Slope == GlobalVar.PriceUp)
                                            {
                                                SetStateInfo(m_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst);
                                                WriteSignalLog("첫신호매수", m_CurSignal);
                                                return m_CurSignal;
                                            }
                                        }
                                        else if (invdivBuySell < 0)
                                        {
                                            if (m_CurWave.Slope == GlobalVar.PriceDown)
                                            {
                                                SetStateInfo(m_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst);
                                                WriteSignalLog("첫신호매도", m_CurSignal);
                                                return m_CurSignal;
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                        default:
                            break;
                    }
                }
            }

            return null;
        }


        public EasyTrader.Signal.PriceSignal FindFirstSignalByHogaAngle(int a_CurIndex, int a_StartHour , int a_StartMin, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            if (m_CurWave == null)
                return null;
            int intTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal)
            {
                intTime = GlobalVar.TimeToInt();
            }
            else
            {
                intTime = GlobalVar.DayIndexToTime(a_CurIndex);
            }

            // 매도, 매수 호가 건수가 발산할 때만 신호를 받을 수 있게 한다.
            double invdivBuySell = m_ETHogaSignalManager.InvDivBuySell;
            int signalStartTime = GlobalVar.TimeToInt(a_StartHour, a_StartMin);
            if (intTime >= signalStartTime)
            {
                if (m_PureForeInfo.Slope() == GlobalVar.PriceUp)
                {
                    switch (Convert.ToInt32(invdivBuySell))
                    {
                        // 기울기가 서로 다른 경우
                        case 1:
                        case 3:
                        case 6:
                            {
                                if (DeltaHogaBuySell >= GlobalVar.DivMinHogaDelta)
                                {
                                    if (m_CurWave.Slope == GlobalVar.PriceUp)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst, ref a_CurSignal);
                                        WriteStateLog("매수(초입)", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                }
                                break;
                            }
                        // 기울기가 서로 같은 경우
                        case 2:
                        case 4:
                        case 5:
                        case 7:
                        case 8:
                        case 9:
                            {
                                if (DeltaHogaBuySell >= GlobalVar.InvMinHogaDelta)
                                {
                                    double deltaAngle = Math.Abs(m_HogaBuyInfo.Angle - m_HogaSellInfo.Angle);
                                    // 각도 차이가 일정값을 넘을 때만 진입을 시도한다.
                                    if (deltaAngle > GlobalVar.FirstMinAngle)
                                    {
                                        if (m_CurWave.Slope == GlobalVar.PriceUp)
                                        {
                                            SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst, ref a_CurSignal);
                                            WriteStateLog("매수(초입)", a_LogFileName, a_CurSignal);
                                            return a_CurSignal;
                                        }
                                    }
                                }
                                break;
                            }
                        default:
                            break;
                    }
                }
                else if (m_PureForeInfo.Slope() == GlobalVar.PriceDown)
                {
                    switch (Convert.ToInt32(invdivBuySell))
                    {
                        // 기울기가 서로 다른 경우
                        case -1:
                        case -3:
                        case -6:
                            {
                                if (DeltaHogaBuySell >= GlobalVar.DivMinHogaDelta)
                                {
                                    if (m_CurWave.Slope == GlobalVar.PriceDown)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst, ref a_CurSignal);
                                        WriteStateLog("매도(초입)", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                }
                                break;
                            }
                        // 기울기가 서로 같은 경우
                        case -2:
                        case -4:
                        case -5:
                        case -7:
                        case -8:
                        case -9:
                            {
                                if (DeltaHogaBuySell >= GlobalVar.InvMinHogaDelta)
                                {
                                    double deltaAngle = Math.Abs(m_HogaBuyInfo.Angle - m_HogaSellInfo.Angle);
                                    // 각도 차이가 일정값을 넘을 때만 진입을 시도한다.
                                    if (deltaAngle > GlobalVar.FirstMinAngle)
                                    {
                                        if (m_CurWave.Slope == GlobalVar.PriceDown)
                                        {
                                            SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst, ref a_CurSignal);
                                            WriteStateLog("매도(초입)", a_LogFileName, a_CurSignal);
                                            return a_CurSignal;
                                        }
                                    }
                                }
                                break;
                            }
                        default:
                            break;
                    }
                }
            }

            return null;
        }

        public EasyTrader.Signal.PriceSignal FindFirstSignalByHogaAngleNHeight(int a_CurIndex, int a_StartHour, int a_StartMin, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurSignal)
        {
            if (m_CurWave == null)
                return null;
            int intTime = 0;
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal)
            {
                intTime = GlobalVar.TimeToInt();
            }
            else
            {
                intTime = GlobalVar.DayIndexToTime(a_CurIndex);
            }

            // 매도, 매수 호가 건수가 발산할 때만 신호를 받을 수 있게 한다.
            double invdivBuySell = m_ETHogaSignalManager.InvDivBuySell;
            int signalStartTime = GlobalVar.TimeToInt(a_StartHour, a_StartMin);
            if (intTime >= signalStartTime && m_PureForeInfo.Height() >= GlobalVar.FirstMinHeight)
            {
                if (m_PureForeInfo.Slope() == GlobalVar.PriceUp)
                {
                    switch (Convert.ToInt32(invdivBuySell))
                    {
                        // 기울기가 서로 다른 경우
                        case 1:
                        case 3:
                        case 6:
                            {
                                if (DeltaHogaBuySell >= GlobalVar.DivMinHogaDelta)
                                {
                                    if (m_CurWave.Slope == GlobalVar.PriceUp)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst, ref a_CurSignal);
                                        WriteStateLog("매수(초입)", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                }
                                break;
                            }
                        // 기울기가 서로 같은 경우
                        case 2:
                        case 4:
                        case 5:
                        case 7:
                        case 8:
                        case 9:
                            {
                                if (DeltaHogaBuySell >= GlobalVar.InvMinHogaDelta)
                                {
                                    double deltaAngle = Math.Abs(m_HogaBuyInfo.Angle - m_HogaSellInfo.Angle);
                                    // 각도 차이가 일정값을 넘을 때만 진입을 시도한다.
                                    if (deltaAngle > GlobalVar.FirstMinAngle)
                                    {
                                        if (m_CurWave.Slope == GlobalVar.PriceUp)
                                        {
                                            SetStateInfo(a_CurIndex, GlobalVar.SignalBuy, GlobalVar.SignalStateFirst, ref a_CurSignal);
                                            WriteStateLog("매수(초입)", a_LogFileName, a_CurSignal);
                                            return a_CurSignal;
                                        }
                                    }
                                }
                                break;
                            }
                        default:
                            break;
                    }
                }
                else if (m_PureForeInfo.Slope() == GlobalVar.PriceDown)
                {
                    switch (Convert.ToInt32(invdivBuySell))
                    {
                        // 기울기가 서로 다른 경우
                        case -1:
                        case -3:
                        case -6:
                            {
                                if (DeltaHogaBuySell >= GlobalVar.DivMinHogaDelta)
                                {
                                    if (m_CurWave.Slope == GlobalVar.PriceDown)
                                    {
                                        SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst, ref a_CurSignal);
                                        WriteStateLog("매도(초입)", a_LogFileName, a_CurSignal);
                                        return a_CurSignal;
                                    }
                                }
                                break;
                            }
                        // 기울기가 서로 같은 경우
                        case -2:
                        case -4:
                        case -5:
                        case -7:
                        case -8:
                        case -9:
                            {
                                if (DeltaHogaBuySell >= GlobalVar.InvMinHogaDelta)
                                {
                                    double deltaAngle = Math.Abs(m_HogaBuyInfo.Angle - m_HogaSellInfo.Angle);
                                    // 각도 차이가 일정값을 넘을 때만 진입을 시도한다.
                                    if (deltaAngle > GlobalVar.FirstMinAngle)
                                    {
                                        if (m_CurWave.Slope == GlobalVar.PriceDown)
                                        {
                                            SetStateInfo(a_CurIndex, GlobalVar.SignalSell, GlobalVar.SignalStateFirst, ref a_CurSignal);
                                            WriteStateLog("매도(초입)", a_LogFileName, a_CurSignal);
                                            return a_CurSignal;
                                        }
                                    }
                                }
                                break;
                            }
                        default:
                            break;
                    }
                }
            }

            return null;
        }

        private EasyTrader.Signal.PriceSignal FindState()
        {
            int signal = GlobalVar.SignalNone;
            // 신호가 하나도 없을 때는 첫번째 신호를 먼저 찾는다.
            if (m_PriceSignalList.Count == 0)
                return FindFirstSignal();
            return FindSignalByComplex();
            /*
            if (GlobalVar.EnableHogaSummitSignal == true)
            {
                signal = m_ETHogaSignalManager.FindHogaSignalBySummit(a_CurIndex);
                if (signal != GlobalVar.SignalNone)
                    return null;
                else
                    return FindSignalByComplex(a_CurIndex);
            }
            else
                return FindSignalByComplex(a_CurIndex);
             */
        }

        public EasyTrader.Signal.PriceSignal FindState(int a_SysType, int a_FirstSig, PriceSignalList a_SignalList, string a_LogFileName, ref EasyTrader.Signal.PriceSignal a_CurState)
        {
            int signalCount = a_SignalList.Count;
            if (a_SysType == GlobalVar.SysTypeHogaSquareOcc)
            {
                return FindSignalHogaSquareOcc(a_SignalList,a_LogFileName, ref a_CurState);
            }
            else if (a_SysType == GlobalVar.SysTypeCallPutSquareOcc)
            {
                return FindSignalCallPutSquareOcc(a_SignalList, a_LogFileName, ref a_CurState);
            }
            else
            {
                if (signalCount == 0)
                    return FindFirstSignalBySysType(a_SysType, a_FirstSig, a_LogFileName, ref a_CurState);
                else
                    return FindSignalBySysType(a_SignalList, a_SysType, a_LogFileName, ref a_CurState);
            }
        }

        private void CheckAddSignal(int a_CurIndex, int a_Signal)
        {
            if (a_Signal == GlobalVar.SignalNone)
                return;

            // 전체 이익이나 손실에 의한 청산
            double totalProfit = CalcTotalProfit(m_ETHighLowSignalManager.CurVal);
            if (GlobalVar.LiquidApplyAll == true)
            {
                if ((GlobalVar.ProfitStopAll > 0 && totalProfit >= GlobalVar.ProfitStopAll) ||
                (GlobalVar.LossStopAll > 0 && totalProfit <= -GlobalVar.LossStopAll))
                {
                    WriteSignalLog(a_CurIndex, a_Signal, "최대손실/이익 제한으로 모두 청산주문 나감");
                    // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                    if (GlobalVar.AutoOrder == true)
                        m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(false,"");
                    return;
                }
            }

            if (IsLastSignalSame(a_Signal) == false)
            {
                int signalTime = 0;
                if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
                    signalTime = GlobalVar.DayIndexToTimeEx(a_CurIndex);
                else
                {
                    signalTime = GlobalVar.TimeToIntEx();
                    // 동일한 시간대에 신호가 발생하면 신호를 거부한다.
                    // 최소 다른 신호가 나오기 1분을 기다린다.
                    if (IsLastSignalSameTime(signalTime) == true)
                    {
                        WriteSignalLog(a_CurIndex, a_Signal, "동시간대 신호발생으로 신호발생 거부");
                        return;
                    }
                }
                EasyTrader.Signal.PriceSignal signal = new EasyTrader.Signal.PriceSignal();
                signal.X = a_CurIndex;
                signal.Y = m_ETHighLowSignalManager.CurVal;
                signal.Type = a_Signal;
                signal.Time = signalTime;

                AddSignal(signal);

                if (a_Signal == GlobalVar.SignalBuy)
                {
                    GlobalVar.PlaySignalBuySound();
                }
                else
                {
                    GlobalVar.PlaySignalSellSound();
                }

                int signalCount = m_PriceSignalList.Count;
                if (signalCount >= GlobalVar.OrderStartSignal && signalCount == GlobalVar.OrderEndSignal)
                {
                    WriteSignalLog(a_CurIndex, a_Signal, "최대신호개수 제한으로 모두 청산주문 나감");
                    // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                    if (GlobalVar.AutoOrder == true)
                        m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(false,"");
                    return;
                }
                // 자동 주문
                if (GlobalVar.AutoOrder == true && 
                    m_ETOrderManager.CanTakeAutoOrder(GlobalVar.TimeToInt()) == true)
                {
                    if (signalCount >= GlobalVar.OrderStartSignal)
                    {
                        int orderType = GlobalVar.OrderNone;
                        if (a_Signal == GlobalVar.SignalBuy)
                        {
                            orderType = GlobalVar.OrderBuy;
                        }
                        else
                        {
                            orderType = GlobalVar.OrderSell;
                        }

                        m_ETOrderManager.SendAutoLiquidAndOrder(orderType, GlobalVar.AutoOrderAmount, m_ETHighLowSignalManager.CurVal);
                    }
                }
            }
        }

        private void SetAutoOrderBySysType(int a_SysType, bool a_AutoOrder)
        {
            if (a_SysType == GlobalVar.SysTypeJisuWaveHogaSummit)
            {
                JisuWaveHogaSummitSysVar.AutoOrder = a_AutoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaWave)
            {
                HogaWaveSysVar.AutoOrder = a_AutoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeJisuWave)
            {
                JisuWaveSysVar.AutoOrder = a_AutoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSquareOcc)
            {
                HogaSquareOccSysVar.AutoOrder = a_AutoOrder;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSummit)
            {
                HogaSummitSysVar.AutoOrder = a_AutoOrder;
            }
        }

        public void SendOrderBySysType(int a_CurIndex, int a_SysType, EasyTrader.Signal.PriceSignal a_Signal, PriceSignalList a_SignalList, string a_HashCode, string a_LogFileName)
        {
            if (a_Signal == null || m_ETOrderManager == null || m_ETHighLowSignalManager == null)
                return;

            bool AutoOrder = GlobalVar.AutoOrder;
            int OrderStartHour = GlobalVar.OrderStartHour;
            int OrderStartMin = GlobalVar.OrderStartMin;
            int OrderEndHour = GlobalVar.OrderEndHour;
            int OrderEndMin = GlobalVar.OrderEndMin;
            int OrderStartSignal = 1;
            int OrderEndSignal = 50;
            int PerOrderAmount = 1;

            if (a_SysType == GlobalVar.SysTypeJisuWaveHogaSummit)
            {
                AutoOrder = JisuWaveHogaSummitSysVar.AutoOrder;
                OrderStartHour = JisuWaveHogaSummitSysVar.OrderStartHour;
                OrderStartMin = JisuWaveHogaSummitSysVar.OrderStartMin;
                OrderEndHour = JisuWaveHogaSummitSysVar.OrderEndHour;
                OrderEndMin = JisuWaveHogaSummitSysVar.OrderEndMin;
                OrderStartSignal = JisuWaveHogaSummitSysVar.SysStartState;
                OrderEndSignal = JisuWaveHogaSummitSysVar.SysEndState;
                PerOrderAmount = JisuWaveHogaSummitSysVar.PerOrderAmount;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaWave)
            {
                AutoOrder = HogaWaveSysVar.AutoOrder;
                OrderStartHour = HogaWaveSysVar.OrderStartHour;
                OrderStartMin = HogaWaveSysVar.OrderStartMin;
                OrderEndHour = HogaWaveSysVar.OrderEndHour;
                OrderEndMin = HogaWaveSysVar.OrderEndMin;
                OrderStartSignal = HogaWaveSysVar.SysStartState;
                OrderEndSignal = HogaWaveSysVar.SysEndState;
                PerOrderAmount = HogaWaveSysVar.PerOrderAmount;
            }
            else if (a_SysType == GlobalVar.SysTypeJisuWave)
            {
                AutoOrder = JisuWaveSysVar.AutoOrder;
                OrderStartHour = JisuWaveSysVar.OrderStartHour;
                OrderStartMin = JisuWaveSysVar.OrderStartMin;
                OrderEndHour = JisuWaveSysVar.OrderEndHour;
                OrderEndMin = JisuWaveSysVar.OrderEndMin;
                OrderStartSignal = JisuWaveSysVar.SysStartState;
                OrderEndSignal = JisuWaveSysVar.SysEndState;
                PerOrderAmount = JisuWaveSysVar.PerOrderAmount;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSquareOcc)
            {
                AutoOrder = HogaSquareOccSysVar.AutoOrder;
                OrderStartHour = HogaSquareOccSysVar.OrderStartHour;
                OrderStartMin = HogaSquareOccSysVar.OrderStartMin;
                OrderEndHour = HogaSquareOccSysVar.OrderEndHour;
                OrderEndMin = HogaSquareOccSysVar.OrderEndMin;
                OrderStartSignal = HogaSquareOccSysVar.SysStartState;
                OrderEndSignal = HogaSquareOccSysVar.SysEndState;
                PerOrderAmount = HogaSquareOccSysVar.PerOrderAmount;
            }
            else if (a_SysType == GlobalVar.SysTypeHogaSummit)
            {
                AutoOrder = HogaSummitSysVar.AutoOrder;
                OrderStartHour = HogaSummitSysVar.OrderStartHour;
                OrderStartMin = HogaSummitSysVar.OrderStartMin;
                OrderEndHour = HogaSummitSysVar.OrderEndHour;
                OrderEndMin = HogaSummitSysVar.OrderEndMin;
                OrderStartSignal = HogaSummitSysVar.SysStartState;
                OrderEndSignal = HogaSummitSysVar.SysEndState;
                PerOrderAmount = HogaSummitSysVar.PerOrderAmount;
            }


            int signalCount = a_SignalList.Count;
            if (signalCount >= OrderStartSignal && signalCount == OrderEndSignal)
            {
                WriteSignalLog(a_CurIndex, a_Signal.Type, "최대신호개수 제한으로 모두 청산주문 나감", a_LogFileName);
                // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                if (AutoOrder == true)
                    m_ETOrderManager.SendAutoLiquid();
                //SignalFired(AutoOrder, a_HashCode);
                SetAutoOrderBySysType(a_SysType, false);
                return;
            }

            // 자동 주문
            if (AutoOrder == true &&
                m_ETOrderManager.CanTakeAutoOrder(GlobalVar.TimeToInt(), OrderStartHour, OrderStartMin, OrderEndHour, OrderEndMin) == true)
            {
                if (signalCount >= OrderStartSignal)
                {
                    if (a_Signal.Type == GlobalVar.SignalBuy)
                    {
                        m_ETOrderManager.SendAutoLiquidAndOrder(GlobalVar.OrderBuy, PerOrderAmount, m_ETHighLowSignalManager.CurVal);
                    }
                    else if (a_Signal.Type == GlobalVar.SignalSell)
                    {
                        m_ETOrderManager.SendAutoLiquidAndOrder(GlobalVar.OrderSell, PerOrderAmount, m_ETHighLowSignalManager.CurVal);
                    }
                    else if (a_Signal.Type == GlobalVar.SignalExitBuy || a_Signal.Type == GlobalVar.SignalExitSell)
                    {
                        m_ETOrderManager.SendAutoLiquid();
                    }
                }
            }
        }


        
        // 주문을 보내는 함수 -
        // a_Signal : 신호 종류
        // a_Single : 참이면 그냥 그대로 주문, 거짓이면 청산후 주문
        public void SendOrder(int a_CurIndex, EasyTrader.Signal.PriceSignal a_Signal, bool a_Single)
        {
            if (a_Signal == null || m_ETOrderManager == null || m_ETHighLowSignalManager == null)
                return;

            int curTime = GlobalVar.DayIndexToTime(a_CurIndex);

            if (GlobalVar.AutoOrder == true)
            {
                // 주문 종료 시간에 자동 청산
                if (curTime == GlobalVar.TimeToInt(GlobalVar.OrderEndHour, GlobalVar.OrderEndMin))
                {
                    m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(false, "");
                    return;
                }

            }

            // 전체 이익에 의한 청산
            double totalProfit = CalcTotalProfit(m_ETHighLowSignalManager.CurVal);
            if (GlobalVar.PerProfitLiquidApply == true)
            {
                if (GlobalVar.ProfitStopAll > 0 && totalProfit >= GlobalVar.ProfitStopAll)
                {
                    WriteSignalLog(a_CurIndex, a_Signal.Type, "최대이익 제한으로 모두 청산주문 나감");
                    // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                    if (GlobalVar.AutoOrder == true)
                        m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(false, "");
                    return;
                }
            }

            if (GlobalVar.PerLossLiquidApply == true)
            {
                if (GlobalVar.LossStopAll > 0 && totalProfit <= -GlobalVar.LossStopAll)
                {
                    WriteSignalLog(a_CurIndex, a_Signal.Type, "최대손실 제한으로 모두 청산주문 나감");
                    // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                    if (GlobalVar.AutoOrder == true)
                        m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(false, "");
                    return;
                }
            }

            int signalCount = m_PriceSignalList.Count;
            if (signalCount >= GlobalVar.OrderStartSignal && signalCount == GlobalVar.OrderEndSignal)
            {
                WriteSignalLog(a_CurIndex, a_Signal.Type, "최대신호개수 제한으로 모두 청산주문 나감");
                // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                if (GlobalVar.AutoOrder == true)
                    m_ETOrderManager.SendAutoLiquid();
                //SignalFired(false, "");
                return;
            }

            // 자동 주문
            if (GlobalVar.AutoOrder == true &&
                m_ETOrderManager.CanTakeAutoOrder(GlobalVar.TimeToInt()) == true)
            {
                if (signalCount >= GlobalVar.OrderStartSignal)
                {
                    if (a_Signal.Type == GlobalVar.SignalBuy)
                    {
                        m_ETOrderManager.SendAutoLiquidAndOrder(GlobalVar.OrderBuy, GlobalVar.AutoOrderAmount, m_ETHighLowSignalManager.CurVal);
                    }
                    else if (a_Signal.Type == GlobalVar.SignalSell)
                    {
                        m_ETOrderManager.SendAutoLiquidAndOrder(GlobalVar.OrderSell, GlobalVar.AutoOrderAmount, m_ETHighLowSignalManager.CurVal);
                    }
                    else if (a_Signal.Type == GlobalVar.SignalExitBuy || a_Signal.Type == GlobalVar.SignalExitSell)
                    {
                        m_ETOrderManager.SendAutoLiquid();
                    }
                }
            }
        }

        public void SendOrder(int a_CurIndex, EasyTrader.Signal.PriceSignal a_Signal, EasyTrader.Order.OrderPacket a_OrderPacket)
        {
            if (a_Signal == null || m_ETOrderManager == null || m_ETHighLowSignalManager == null)
                return;

            int curTime = GlobalVar.DayIndexToTime(a_CurIndex);

            if (a_OrderPacket.AutoOrder == true)
            {
                // 주문 종료 시간에 자동 청산
                if (curTime == GlobalVar.TimeToInt(a_OrderPacket.EndHour, a_OrderPacket.EndMin))
                {
                    m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(false, "");
                    return;
                }

            }

            // 전체 이익에 의한 청산
            if (a_OrderPacket.EnableProfitStop == true)
            {
                if (a_OrderPacket.ProfitStopValue > 0 && a_OrderPacket.TotalProfit >= a_OrderPacket.ProfitStopValue)
                {
                    WriteSignalLog(a_CurIndex, a_Signal.Type, "최대이익 제한으로 모두 청산주문 나감");
                    // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                    if (a_OrderPacket.AutoOrder == true)
                        m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(false, "");
                    return;
                }
            }

            if (a_OrderPacket.EnableLossStop == true)
            {
                if (a_OrderPacket.LossStopValue > 0 && a_OrderPacket.TotalProfit <= -a_OrderPacket.LossStopValue)
                {
                    WriteSignalLog(a_CurIndex, a_Signal.Type, "최대손실 제한으로 모두 청산주문 나감");
                    // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                    if (a_OrderPacket.AutoOrder == true)
                        m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(false, "");
                    return;
                }
            }

            int signalCount = m_PriceSignalList.Count;
            if (signalCount >= a_OrderPacket.StartSignal && signalCount == a_OrderPacket.EndSignal)
            {
                WriteSignalLog(a_CurIndex, a_Signal.Type, "최대신호개수 제한으로 모두 청산주문 나감");
                // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                if (a_OrderPacket.AutoOrder == true)
                    m_ETOrderManager.SendAutoLiquid();
                //SignalFired(false, "");
                return;
            }

            // 자동 주문
            if (a_OrderPacket.AutoOrder &&
                m_ETOrderManager.CanTakeAutoOrder(GlobalVar.TimeToInt()) == true)
            {
                if (signalCount >= a_OrderPacket.StartSignal)
                {
                    if (a_Signal.Type == GlobalVar.SignalBuy)
                    {
                        m_ETOrderManager.SendAutoLiquidAndOrder(GlobalVar.OrderBuy, a_OrderPacket.PerOrderAmount, m_ETHighLowSignalManager.CurVal);
                    }
                    else if (a_Signal.Type == GlobalVar.SignalSell)
                    {
                        m_ETOrderManager.SendAutoLiquidAndOrder(GlobalVar.OrderSell, a_OrderPacket.PerOrderAmount, m_ETHighLowSignalManager.CurVal);
                    }
                    else if (a_Signal.Type == GlobalVar.SignalExitBuy || a_Signal.Type == GlobalVar.SignalExitSell)
                    {
                        m_ETOrderManager.SendAutoLiquid();
                    }
                }
            }
        }

        // 주문을 보내는 함수 -
        // a_Signal : 신호 종류
        // a_Single : 참이면 그냥 그대로 주문, 거짓이면 청산후 주문
        private void SendOrder(EasyTrader.Signal.PriceSignal a_Signal, bool a_Single)
        {
            if (a_Signal == null || m_ETOrderManager == null || m_ETHighLowSignalManager == null)
                return;
            int a_CurIndex = GlobalVar.DayIndex();
            int curTime = GlobalVar.DayIndexToTime(a_CurIndex);

            if (GlobalVar.AutoOrder == true)
            {
                // 주문 종료 시간에 자동 청산
                if (curTime == GlobalVar.TimeToInt(GlobalVar.OrderEndHour, GlobalVar.OrderEndMin))
                {
                    m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(false, "");
                    return;
                }

            }

            // 전체 이익에 의한 청산
            double totalProfit = CalcTotalProfit(m_ETHighLowSignalManager.CurVal);
            if (GlobalVar.PerProfitLiquidApply == true)
            {
                if (GlobalVar.ProfitStopAll > 0 && totalProfit >= GlobalVar.ProfitStopAll)
                {
                    WriteSignalLog(a_CurIndex, a_Signal.Type, "최대이익 제한으로 모두 청산주문 나감");
                    // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                    if (GlobalVar.AutoOrder == true)
                        m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(false, "");
                    return;
                }
            }

            if (GlobalVar.PerLossLiquidApply == true)
            {
                if (GlobalVar.LossStopAll > 0 && totalProfit <= -GlobalVar.LossStopAll)
                {
                    WriteSignalLog(a_CurIndex, a_Signal.Type, "최대손실 제한으로 모두 청산주문 나감");
                    // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                    if (GlobalVar.AutoOrder == true)
                        m_ETOrderManager.SendAutoLiquid();
                    //SignalFired(false, "");
                    return;
                }
            }

            int signalCount = m_PriceSignalList.Count;
            if (signalCount >= GlobalVar.OrderStartSignal && signalCount == GlobalVar.OrderEndSignal)
            {
                WriteSignalLog(a_CurIndex, a_Signal.Type, "최대신호개수 제한으로 모두 청산주문 나감");
                // 자동 주문이 설정되어 있을 때만 모두 청산을 내보낸다.
                if (GlobalVar.AutoOrder == true)
                    m_ETOrderManager.SendAutoLiquid();
                //SignalFired(false, "");
                return;
            }

            // 자동 주문
            if (GlobalVar.AutoOrder == true &&
                m_ETOrderManager.CanTakeAutoOrder(GlobalVar.TimeToInt()) == true)
            {
                if (signalCount >= GlobalVar.OrderStartSignal)
                {
                    if (a_Signal.Type == GlobalVar.SignalBuy)
                    {
                        m_ETOrderManager.SendAutoLiquidAndOrder(GlobalVar.OrderBuy, GlobalVar.AutoOrderAmount, m_ETHighLowSignalManager.CurVal);
                    }
                    else if (a_Signal.Type == GlobalVar.SignalSell)
                    {
                        m_ETOrderManager.SendAutoLiquidAndOrder(GlobalVar.OrderSell, GlobalVar.AutoOrderAmount, m_ETHighLowSignalManager.CurVal);
                    }
                    else if (a_Signal.Type == GlobalVar.SignalExitBuy || a_Signal.Type == GlobalVar.SignalExitSell)
                    {
                        m_ETOrderManager.SendAutoLiquid();
                    }
                }
            }
        }

        public EasyTrader.Signal.PriceSignal CheckAddSignal(int a_CurIndex, PriceSignalList a_SignalList, EasyTrader.Signal.PriceSignal a_Signal)
        {
            if (a_Signal == null || a_SignalList == null)
                return null;

            if (IsLastSignalSame(a_SignalList, a_Signal.Type) == false)
            {
                int signalTime = 0;
                if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
                    signalTime = GlobalVar.DayIndexToTimeEx(a_CurIndex);
                else
                {
                    signalTime = GlobalVar.TimeToIntEx();
                    // 동일한 시간대에 신호가 발생하면 신호를 거부한다.
                    // 최소 다른 신호가 나오기 1분을 기다린다.
                    if (IsLastSignalSameTime(a_SignalList, signalTime) == true)
                    {
                        WriteSignalLog(a_CurIndex, a_Signal.Type, "동시간대 신호발생으로 신호발생 거부");
                        return null;
                    }
                }
                EasyTrader.Signal.PriceSignal signal = a_Signal.Clone();

                AddSignal(a_SignalList, signal);

                if (a_Signal.Type == GlobalVar.SignalBuy)
                {
                    GlobalVar.PlaySignalBuySound();
                }
                else if (a_Signal.Type == GlobalVar.SignalSell)
                {
                    GlobalVar.PlaySignalSellSound();
                }
                else if (a_Signal.Type == GlobalVar.SignalExitBuy)
                {
                    GlobalVar.PlaySignalSellSound();
                }
                else if (a_Signal.Type == GlobalVar.SignalExitSell)
                {
                    GlobalVar.PlaySignalBuySound();
                }

                return signal;
            }

            return null;
        }

        public EasyTrader.Signal.PriceSignal CheckAddSignal(int a_CurIndex, PriceSignalList a_SignalList, EasyTrader.Signal.PriceSignal a_Signal, string a_LogFileName)
        {
            if (a_Signal == null || a_SignalList == null)
                return null;

            if (IsLastSignalSame(a_SignalList, a_Signal.Type) == false)
            {
                EasyTrader.Signal.PriceSignal signal = a_Signal.Clone();

                AddSignal(a_SignalList, signal);

                return signal;
            }

            return null;
        }

        public EasyTrader.Signal.PriceSignal CheckAddState(int a_CurIndex, PriceSignalList a_SignalList, EasyTrader.Signal.PriceSignal a_Signal)
        {
            if (a_Signal == null || a_SignalList == null)
                return null;

            if (IsLastSignalSame(a_SignalList, a_Signal.Type) == false)
            {
                int signalTime = 0;
                if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
                    signalTime = GlobalVar.DayIndexToTimeEx(a_CurIndex);
                else
                {
                    signalTime = GlobalVar.TimeToIntEx();
                    // 동일한 시간대에 신호가 발생하면 신호를 거부한다.
                    // 최소 다른 신호가 나오기 1분을 기다린다.
                    if (IsLastSignalSameTime(a_SignalList, signalTime) == true)
                    {
                        return null;
                    }
                }
                EasyTrader.Signal.PriceSignal signal = a_Signal.Clone();

                AddSignal(a_SignalList, signal);

                return signal;
            }

            return null;
        }


        public EasyTrader.Signal.PriceSignal CheckAddSignal(PriceSignalList a_SignalList, EasyTrader.Signal.PriceSignal a_Signal)
        {
            if (a_Signal == null || a_SignalList == null)
                return null;

            if (IsLastSignalSame(a_SignalList, a_Signal.Type) == false)
            {
                EasyTrader.Signal.PriceSignal signal = a_Signal.Clone();
                AddSignal(a_SignalList, signal);
                return signal;
            }

            return null;
        }

        private EasyTrader.Signal.PriceSignal CheckAddSignal(int a_CurIndex, EasyTrader.Signal.PriceSignal a_Signal)
        {
            if (a_Signal == null)
                return null;

            if (IsLastSignalSame(a_Signal.Type) == false)
            {
                int signalTime = 0;
                if (GlobalVar.OperationMode == GlobalVar.OperationModeSimul)
                    signalTime = GlobalVar.DayIndexToTimeEx(a_CurIndex);
                else
                {
                    signalTime = GlobalVar.TimeToIntEx();
                    // 동일한 시간대에 신호가 발생하면 신호를 거부한다.
                    // 최소 다른 신호가 나오기 1분을 기다린다.
                    if (IsLastSignalSameTime(signalTime) == true)
                    {
                        WriteSignalLog(a_CurIndex, a_Signal.Type, "동시간대 신호발생으로 신호발생 거부");
                        return null;
                    }
                }
                EasyTrader.Signal.PriceSignal signal = a_Signal.Clone();

                AddSignal(signal);

                if (a_Signal.Type == GlobalVar.SignalBuy)
                {
                    GlobalVar.PlaySignalBuySound();
                }
                else if (a_Signal.Type == GlobalVar.SignalSell)
                {
                    GlobalVar.PlaySignalSellSound();
                }
                else if (a_Signal.Type == GlobalVar.SignalExitBuy)
                {
                    GlobalVar.PlaySignalSellSound();
                }
                else if (a_Signal.Type == GlobalVar.SignalExitSell)
                {
                    GlobalVar.PlaySignalBuySound();
                }

                return signal;
            }

            return null;
        }
    }
}
